Checking for keywords in several lists
Emile van Sebille
emile at fenx.com
Thu Jan 24 08:05:19 EST 2002
"Heiko Wolf" <heiko.wolf at dlr.de> wrote in message
news:d013da35.0201240248.6b233b95 at posting.google.com...
> 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,
'word3':function2,'word4':function2}
then your code would look like:
try: all_words[string]()
except KeyError: handle_error(string)
HTH,
--
Emile van Sebille
emile at fenx.com
---------
More information about the Python-list
mailing list