How to check if a list contains an item

Esmail ebonak at
Sun Apr 12 21:26:45 CEST 2009 at 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?


More information about the Python-list mailing list