Is there something similar to list comprehension in dict?

Stefan Behnel stefan_ml at behnel.de
Fri Nov 20 03:26:21 EST 2009


Stefan Behnel, 20.11.2009 09:24:
> You can use  d.update(...)
> 
> It accepts both another dict as well as a generator expression that
> produces item tuples, e.g.
> 
>     d.update( (i, i**2) for i in range(10) )

This also works, BTW:

    >>> d = {}
    >>> d.update(value=5)
    >>> d
    {'value': 5}

Stefan



More information about the Python-list mailing list