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

Garry Knight garryknight at gmx.net
Mon Mar 22 16:11:58 EST 2004


In message <6d6b80e0.0403220202.356f62fc at posting.google.com>, MarieR wrote:

> I want to check whether the string 'Remove' is present in a list
> 'supportList', but if I do
> 
> if ('Remove') in supportList:
> 
> or
> 
> if 'Remove' in supportList:
> 
> I get the error message
> 
> 'in ' requires character as left operand.

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

-- 
Garry Knight
garryknight at gmx.net  ICQ 126351135
Linux registered user 182025



More information about the Python-list mailing list