Anyway to clarify this code? (dictionaries)

bonono at gmail.com bonono at gmail.com
Tue Nov 22 22:52:40 EST 2005


Bengt Richter wrote:
>  >>> def my_search(another, keys, x): return dict((k,another[k]) for k in keys if another[k]>x)
>  ...
>  >>> my_search(another, 'cb', .3)
>  {'b': 0.35806602909756235}
>  >>> my_search(another, 'abcd', .4)
>  {'a': 0.60649466203365532, 'd': 0.77440643221840166}
> 
Do you need to guard the case "k not in another" ?




More information about the Python-list mailing list