A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-November/030298.html below:

[Python-Dev] dict() enhancement idea?

[Python-Dev] dict() enhancement idea? [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.

Thomas




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4