How to check if a list contains an item

Peter Otten __peter__ at web.de
Sun Apr 12 15:26:59 EDT 2009


online.service.com at gmail.com wrote:

> python doesn't have a list.contains()   method?

It has. It's called list.__contains__() and used indirectly through the 'in'
operator:

>>> "red" in ["red", "green", "blue"]
True
>>> "yellow" in ["red", "green", "blue"]
False




More information about the Python-list mailing list