473,505 Members | 15,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1496
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
33324
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
24
2027
by: Steven Bethard | last post by:
I think one of the biggest reasons we're having such problems coming to any agreement on decorator syntax is that each proposal makes a number of syntax decisions, not just one. For decorators, I...
5
854
by: ST | last post by:
Hi, I'm sort of in a rush here...I'm sort of new to vb.net and I'm trying to write the syntax to check a sql table to see if the record already exists based on firstname and lastname text fields...
4
2566
by: yaffa | last post by:
dear folks, i'm trying to append a semicolon to my addr string and am using the syntax below. for some reason the added on of the ; doesn't work. when i print it out later on it only shows the...
18
4705
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
16
1745
by: danu | last post by:
I have a structure : typedef struct{ char magicNum; int width; int height; int maxGrey; int pixels; } ImageT;
12
1673
by: Brad Baker | last post by:
I am trying to write a simple ASP.net/C# page which allows users to select some values and produce a report based on a SQL query. I have a self posting dropdown form which allows users to select...
17
2013
by: Dinsdale | last post by:
I would like to compare a string value to a pre-determined list of other strings. Is there a simple way to do this in one statements like this: if(strMystring.ToUpper() == ("STRING1"| "STRING2"|...
7
2866
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM",...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.