python - How to find the position of specific element in a list? -
i have list this:
website = ['http://freshtutorial.com/install-xamp-ubuntu/', 'http://linuxg.net/how-to-install-xampp-on-ubuntu-13-04-12-10-12-04/', 'http://ubuntuforums.org/showthread.php?t=2149654', 'http://andyhat.co.uk/2012/07/installing-xampp-32bit-ubuntu-11-10-12-04/', 'http://askubuntu.com/questions/303068/error-with-tar-command-cannot-install-xampp-1-8-1-on-ubuntu-13-04', 'http://askubuntu.com/questions/73541/how-to-install-xampp']
i want search if following list contain url or not.
url in format : url = 'http://freshtutorial.com'
the website 1st element of list. thus, want print 1 not 0.
i want in loop if there's no website url, go again , dynamically generate list , again search website.
i have done upto now:
for in website: if url in website: print "true"
i can't seem print position , wrap in loop. also, better use regex
or if in that
syntax. thanks
here complete program:
def search(li,ur): u in li: if u.startswith(ur): return li.index(u)+1 return 0 def main(): website = ['http://freshtutorial.com/install-xamp-ubuntu/', 'http://linuxg.net/how-to-install-xampp-on-ubuntu-13-04-12-10-12-04/', 'http://ubuntuforums.org/showthread.php?t=2149654', 'http://andyhat.co.uk/2012/07/installing-xampp-32bit-ubuntu-11-10-12-04/', 'http://askubuntu.com/questions/303068/error-with-tar-command-cannot-install-xampp-1-8-1-on-ubuntu-13-04', 'http://askubuntu.com/questions/73541/how-to-install-xampp'] url = 'http://freshtutorial.com' print search(website,url) if __name__ == '__main__': main()
Comments
Post a Comment