Checking for keywords in several lists
Heiko Wolf
heiko.wolf at dlr.de
Thu Jan 24 05:48:06 EST 2002
Hi,
imagine some lists of strings like
list1_words = ('word1','word2')
list2_words = ('word3','word4')
Now I want to check if string is whether in list1_words or in
list2_words. I can do that by
if string in list1_words:
do something
elif string in list2_words:
do something else
But if these lists get more, it is very uncomfortable doing it the
if/elif -way.
Any other suggestions?
I thought of something like
list1_words = ('word1','word2','function1')
list2_words = ('word3','word4','function2')
if string in *_words
execute *_words[2]
to execute the funtion that is given in that list.
I know that it doesn't work exactly that way, but perhaps someone
knows something that leads to such a function...
Cheers, Heiko
More information about the Python-list
mailing list