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