470,614 Members | 1,528 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

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

Hi,

Sorry for my newbie question:

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.

Thanks in advance for your help,

Marie
Jul 18 '05 #1
4 1448
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.


for i in supportList:
if i == 'Remove':
doSomething()

I am sure there is a shorter way, but this will work.

Bjoern
Jul 18 '05 #2
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.


It likely means that supportList is not what you think it is.

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ There's a reason why we / Keep chasing morning
-- Sandra St. Victor
Jul 18 '05 #3
On 22 Mar 2004 02:02:51 -0800, ro******@esrf.fr (MarieR) wrote:
Hi,

Sorry for my newbie question:

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.

Thanks in advance for your help,

Marie

What perfect timing--the question right before yours asked which
version of Python added support for that syntax. You need to be using
2.3 or newer to use the 'in' operator to search for a string in a
string.
--dang
Jul 18 '05 #4
In message <6d**************************@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
ga*********@gmx.net ICQ 126351135
Linux registered user 182025
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

699 posts views Thread by mike420 | last post: by
24 posts views Thread by Steven Bethard | last post: by
4 posts views Thread by yaffa | last post: by
16 posts views Thread by danu | last post: by
12 posts views Thread by Brad Baker | last post: by
17 posts views Thread by Dinsdale | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.