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)

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to