Q:

Issue with List count method

The Program I need help is written below
def countHits(file):    
        f2 = open(file,'rU')    
        l2 = f2.readlines()    
        f2.close()    
        user_input = raw_input("Enter the URL that you wish to chck fr the nmber of Hits")     
        print "The number of HITS for the given STRING/URL is : %s"%(l2.count(user_input))

def main():    
        strin = raw_input("Enter the file name\n")    
        countHits(strin)

if __name__ == '__main__':

   main()

The file given as input contains list of urls (mentioned below): 
/RLSsdTfswds/images//innercontainer-collapse.gif    
/RL/css/default.css    
/RLSTsdsdRdsdU/scripts/highslide/graphics/outlines/rounded-white.png    
/RLSsdsdTsdsRsddU/scripts/highslide/graphics/zoomout.cur    
/RLS/css/highslide/highslide/graphics/loader.white.gif    
/RL/css/default.css    
/RLST/rws/scripts/processschScript.js    
/RLSR/scripts/NumberFormat.js    
/RL/css/default.css

My query is that when I try to find url "/RL/css/default.css", the program doesn't gives me the count. Help me where I'm making a mistake ?

A:

Possible solution: 

def countHits(file):    
    f2 = open(file,'rU')    
    l2 = f2.readlines()    
    f2.close()
    l2 = [l.strip() for l in l2]
    user_input = raw_input(
       "Enter the URL that you wish to chck fr the nmber of Hits"
    )   
    print "The number of HITS for the given STRING/URL is : %s"% (
       l2.count(user_input)
    )

I guess this will work faster. 

def countHits(file):    
    f2 = open(file,'rU')    
    l2 = f2.readlines()    
    f2.close()
    l2 = map(lambda x: x.strip(), l2)
    user_input = raw_input(
       "Enter the URL that you wish to chck fr the nmber of Hits"
    )   
    print "The number of HITS for the given STRING/URL is : %s"% (
       l2.count(user_input)
    )

