Richard Neumann <r.neum...@homeinfo.de> added the comment:

Maybe there is no need to sacrifice performance, if a new, optional keyword 
argument would be introduced to dict.items():

    def items(self, named=False):
        if named:
            <yield namedtuples>
        else:
            <current behaviour>

Currently I need to define a namedtuple everywhere I do this and starmap the 
dicts' items.

It'd be nice to have this option built-in or a new collections class like:

    from collections import namedtuple
    from itertools import starmap


    DictItem = namedtuple('DictItem', ('key', 'value'))


    class NamedDict(dict):
        """Dictionary that yields named tuples on item iterations."""

        def items(self):
            """Yields DictItem named tuples."""
            return starmap(DictItem, super().items())

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31992>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to