3 ms·
Isn’t the whole point of named tuples to not iterate over indexes, but to iterate over field names instead, e.g employee.name, employee.salary? You can also us
by csunbird 3y ago
Isn’t the whole point of named tuples to not iterate over indexes, but to iterate over field names instead, e.g employee.name, employee.salary?
You can also use typing.namedtuple as a baseclass for your classes to have the same functionality .
- Kwpolska 3y agoNamed tuples have both field names and numeric indexes. If you iterate over a namedtuple, you just get the values. The field names are hidden in a _fields attribute, there is no way to iterate over (name, value) pairs.
- quietbritishjim 3y ago> there is no way to iterate over (name, value) pairs zip(x._fields, x) I get your point that it's not just a built in method though.