Beginner question

Fábio Santos fabiosantosart at gmail.com
Tue Jun 4 08:15:18 EDT 2013


On 4 Jun 2013 12:57, "Carlos Nepomuceno" <carlosnepomuceno at outlook.com>
wrote:
>
> >On 4 Jun 2013 12:28, "Carlos Nepomuceno" <carlosnepomuceno at outlook.com>
wrote:
> [...]
>
> >> What's going on? Is there a way to make dict() to resolve the
variables?
> >Well yes.
> >dict(**{a:0,b:1})
> >The dict() constructor makes a dictionary from keyword arguments. So you
just have to feed it keyword arguments using **.
> >And if you're in a bad day,
> >dict(**locals())
>
> That's exactly the same!
> >>>dict(**{a:0,b:1})=={a:0,b:1}
> True
>
> Are there any benefits from using dict() instead of {}?

Other than being able to create a dict from a list of tuples, and copying a
dict using dict(anotherdict.items()), not that I know of.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130604/54740987/attachment.html>


More information about the Python-list mailing list