How to check whether a list have specific value exist or not?
Heiko Wundram
modelnine at ceosg.de
Sat Apr 9 05:48:27 EDT 2005
Am Samstag, 9. April 2005 11:37 schrieb Michael Spencer:
> praba kar wrote:
> > I want to check a list have specific
> > value or not. So If any one know regarding this
> > mail me
> A minute of two experimenting, would then lead you to:
> >>> l = [1,2,3,4,5]
> >>> l.index(3)
>
> 2
Or, if its that you just want to know whether a value is somewhere in an
iterable:
>>> l = [1,2,3,4,5]
>>> 4 in l
True
See how there is special syntax to call the __contains__ method of the
iterable automatically.
--
--- Heiko.
listening to: Pearl Jam - Rearviewmirror
see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050409/1551afc9/attachment.sig>
More information about the Python-list
mailing list