Message306028
| Author | Richard Neumann |
|---|---|
| Recipients | Richard Neumann, eric.smith, rhettinger, serhiy.storchaka |
| Date | 2017-11-10.12:55:54 |
| SpamBayes Score | -1.0 |
| Marked as misclassified | Yes |
| Message-id | <1510318554.79.0.213398074469.issue31992@psf.upfronthosting.co.za> |
| In-reply-to |
| Content | |
|---|---|
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()) |
|
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2017-11-10 12:55:54 | Richard Neumann | set | recipients: + Richard Neumann, rhettinger, eric.smith, serhiy.storchaka |
| 2017-11-10 12:55:54 | Richard Neumann | set | messageid: <1510318554.79.0.213398074469.issue31992@psf.upfronthosting.co.za> |
| 2017-11-10 12:55:54 | Richard Neumann | link | issue31992 messages |
| 2017-11-10 12:55:54 | Richard Neumann | create | |