Can this Python code be further shrunk?
Question: Below is Python code that fetches all of the sub-domains within a domain. It
takes a file as input that contains the page source for a website. The second
argument is the domain name. For example: `"https://www.sometime.com"`.

    
    
    import re
    def getSubDomains(fil,domain):
       with open(fil) as f:
        subDomainLst = []
        for line in f:
          m = re.findall(r'\bhref="\https://[\w+\.*]+%s/'%domain,line)
          if(m):
             for ele in m: subDomainLst.append(ele.split('/')[2])
          else:
                continue
       subDomainLst = list(set(subDomainLst))
       for ele in subDomainLst: print ele 
    def main():
        fil1,domain1 = raw_input("Enter the file name\n"),raw_input("Enter the domain\n")
        getSubDomains(fil1,domain1)
    main() if __name__ == '__main__' else Pass
    

I've tried shrinking the inner 'if else statement' to

    
    
    for ele in m: subDomainLst.append(ele.split('/')[2]) if(m) else continue
    

But this gives an error.

Can the above code be shrunk further (16 lines for now) so that it takes up
minimum number of lines and become more pythonic?


Answer: You don't need to add _continue_. You can try doing like this, even though I
DO NOT recommend as it makes the code unreadable.

    
    
    subDomainLst = [ele.split('/')[2] for line in f for ele in re.findall(r'\bhref="\https://[\w+\.*]+%s/' % domain, line)]
    

Btw you should indent your code by 4 spaces and try to avoid one-line
uncomprehensible statements: pythonic means also readable

Complete code:

    
    
    if __name__ == '__main__':
        import re 
        fil, domain = raw_input("Enter the file name\n"), raw_input("Enter the domain\n")
        with open(fil) as f:
            print '\n'.join([ele.split('/')[2] for line in f for ele in re.findall(r'\bhref="\https://[\w+\.*]+%s/' % domain, line)])
    

