Why does Python show the whole array?

Qilong Ren qilong.ren at gmail.com
Wed Apr 8 08:19:58 EDT 2009


>

Remeber the return value of find function of a string is -1 when it  
fails, which is True.

Try:
   for item in isp:
      if item in test:
        print item



> From: Gilles Ganault <nospam at nospam.com>
> Date: April 8, 2009 5:56:34 PM CST
> To: python-list at python.org
> Subject: Why does Python show the whole array?
>
>
> Hello
>
> 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
> gmail.com
> yahoo.com
> =======
>
> Any idea why I'm also getting "yahoo.com"?
>
> Thank you.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090408/b28ecb3d/attachment-0001.html>


More information about the Python-list mailing list