Checking for keywords in several lists

Emile van Sebille emile at
Thu Jan 24 14:05:19 CET 2002

"Heiko Wolf" <heiko.wolf at> wrote in message
news:d013da35.0201240248.6b233b95 at

> 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...

Perhaps you could restructure to using a dict of the form:

all_words = {'word1':function1,'word2':function1,

then your code would look like:

try: all_words[string]()
except KeyError: handle_error(string)



Emile van Sebille
emile at


More information about the Python-list mailing list