30.11.19 23:16, Soni L. пише:
It'd be quite nice if dict.items() returned a namedtuple so all these x[0], x[1], el[0], el[1], etc would instead be x.key, x.value, el.key, el.value, etc. It would be more readable and more maintainable.
It was discussed before. The problem is that creating, using and destroying a tuple is much faster than a named tuple. Many parts of Python have special optimizations for tuples. It is critical for the whole Python. So making dict.items() returning named tuples will harm every Python program. Also unpacking a tuple and using local variables key and value is faster and more convenient than using attribute access. Tuples is one of the best thing in Python. Let enjoy of using them and do not make the life harder.