How to check if a list contains an item

Esmail ebonak at hotmail.com
Sun Apr 12 15:26:45 EDT 2009


online.service.com at gmail.com wrote:
> python doesn't have a list.contains()   method?
> 

How about the 'in' operator?

In [1]: l1=['aa', 'bb', 'cc']

In [2]: 'aa' in l1
Out[2]: True

In [3]: 'ab' in l1
Out[3]: False

In [4]: 'cc' in l1
Out[4]: True

Will this help?

Esmail





More information about the Python-list mailing list