Syntax of 'in' : searching a list for a string

Greg Ewing (using news.cis.dfn.de) ieyf4fu02 at sneakemail.com
Wed Mar 24 22:41:23 EST 2004


Garry Knight wrote:
> If supportList is a list of strings, then this should work in Python 2.3 and
> above:
> 
> for i in supportList:
>   if 'Remove' in i:
>     print 'Found it in', i

But you only need that if you're looking for a string that
contains 'Remove' rather than one that exactly equals
'Remove'.

If you're looking for an exact match, the original version
should work in any version of Python.

It looks more like the OP's problem was that supportList
was actually a string rather than a list of strings.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list