[Python-Dev] Analog of PEP 448 for dicts (unpacking in assignment with dict rhs) (original) (raw)

Serhiy Storchaka storchaka at gmail.com
Sun Nov 12 10:43:53 EST 2017


12.11.17 12:06, Nick Coghlan пише:

So if folks would like dict unpacking syntax, then a suitable place to start would be a proposal for a "getitems" builtin that allowed operations like:

b, a = getitems(d, ("b", "a")) operator.itemgetter and operator.attrgetter may provide some inspiration for possible proposals.

I don't see any relations between this getitems and operator.itemgetter or operator.attrgetter. getitems can be implemented as:

(the most obvious way)

 def getitems(mapping, keys):
     for key in keys:
         yield mapping[key]

or

 def getitems(mapping, keys):
     return map(functools.partial(operator.getitem, mapping), keys)

or (simpler but rough equivalent)

 def getitems(mapping, keys):
     return map(mapping.__getitem__, keys)


More information about the Python-Dev mailing list