Why does Python show the whole array?
davea at ieee.org
Wed Apr 8 12:44:10 CEST 2009
Gilles Ganault wrote:
> I'd like to go through a list of e-mail addresses, and extract those
> that belong to well-known ISP's. For some reason I can't figure out,
> Python shows the whole list instead of just e-mails that match:
> ======= script
> test = "toto at gmail.com"
> isp = ["gmail.com", "yahoo.com"]
> for item in isp:
> if test.find(item):
> print item
> ======= output
> Any idea why I'm also getting "yahoo.com"?
> Thank you.
Look up the definition of string.find(). It returns a -1 for failure,
not 0. So your test should presumably be
if test.find(item) != -1:
More information about the Python-list