if 'hallo' in ['hallooo','halloooooooo'] problem
Robert
rmanx at gmx.de
Thu Apr 8 10:36:56 EDT 2004
Sorry!!!!
the example I gave I did not check. Of course it works.
The problem is somewhere else. My programm was doing this:
if 'hallo' in 'hallooooo':
....
instead of (what I was thinking):
if 'hallo' in ['hallo']:
....
so , everything is fine. I did not see, that the variable holding the second
string is a string instead of a list.
Thanks for your replies!!!!!!
"Robert" <rmanx at gmx.de> wrote in message
news:c53k55$mm2$1 at news.mch.sbs.de...
> Hi,
>
> I have a little problem and mybe one of you has got the solution.
> I would like to check if a string is in a list of strings.
> The following returns true:
> if 'hallo' in ['halloooo','hallooooooooo']:
> pass
>
> but I want to check if the string is exactly equal to any string in the
> list.
> How can I do this without the need to do something like this:
> def stringInList(self,string,list):
> for oneStr in list:
> if string == oneStr:
> return 1
> return 0
>
>
> Thank you in advance,
>
> Robert
>
>
More information about the Python-list
mailing list