acting on items passed to a method via a dictiomary

Ville Vainio ville at spammers.com
Fri Oct 15 14:54:04 EDT 2004


>>>>> "Ville" == Ville Vainio <ville at spammers.com> writes:

    Ville> def dictget(d, key):
    Ville>   if key in d: 
    Ville>     yield d[key]
    Ville>   return

After putting down the crack pipe, I realized you can also do

def dictget(d,key):
    if key in d: 
        return [d[key]]
    return []

which is slightly less clever/cute. Too lazy to compare performance
right now.


-- 
Ville Vainio   http://tinyurl.com/2prnb



More information about the Python-list mailing list