[Python-Dev] dict() enhancement idea?

Thomas Heller theller@python.net
21 Nov 2002 17:35:15 +0100

Just van Rossum <just@letterror.com> writes:

> I sometimes use an idiom like
>   def dictfromkeywords(**kwargs):
>       return kwargs
>   d = dictfromkeywords(
>           akey = 12,
>           anotherkey = "foo",
>           ...etc.
>   )

For me it's usually spelled a shorter way:

    def DICT(**kw): return kw

    d = DICT(akey=12, anotherkey="foo")

Looks nicer than the long name, IMO, and complements 'dict'.

> It just occured to me that the dict constructor could easily be overloaded with
> this behavior: it currently takes no keyword arguments[*], so the kwargs dict
> could simply be used to initialize the new dict.

Usually I do not create dictionaries by calling the constructor,
because I never can remember which arguments I have to use.

This change would make me change my mind again to use it again, so a +1.