Checking for keywords in several lists

Heiko Wolf heiko.wolf at dlr.de
Thu Jan 24 09:29:38 EST 2002


"Alex Martelli" <aleax at aleax.it> wrote in message news:<a2oqpc$77q$1 at serv1.iunet.it>...
>> "Heiko Wolf" <heiko.wolf at dlr.de> wrote in message
>> news:d013da35.0201240248.6b233b95 at posting.google.com...
>> Any other suggestions?
> 
> A simple approach might be:
> 
> for function, wordlist in (
>     dosomething, ('word1', 'word2', 'word3'),
>     dosomethingelse, ('word4', 'word5'),
>     yetanothercase, ('word6', 'word7', 'word8')):
>         if theword in wordlist:
>             function()
>             break
> else:
>     # theword is in none of the lists, do
>     # some default action here
>         adefaultaction()
> 
> where each of dosomething, dosomethingelse, yetanothercase and
> adefaultaction are functions (or other callables) written to
> be called without arguments.  Not the NAMES of the functions,
> mind: the function themselves.
>  

I tried your approach, but it hit me with a TypeError.

    for function, wordlist in (
TypeError: unpack non-sequence

What am I doing wrong?

Cheers, Heiko



More information about the Python-list mailing list