By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,543 Members | 1,320 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,543 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.