[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Why so much use of ‘dict.iter*’ (was: Python 2, Python 3, Stretch & Buster)



Barry Warsaw <barry@debian.org> writes:

> Personally, I think the use of dict.iteritems is way overused.

It (as the trio of ‘dict.iterkeys’, ‘dict.itervalues’, ‘dict.iteritems’)
was heavily recommended from the time when the standard recommendation
was to use ‘2to3’. That tool could then tell whether the programmer
actually wanted the list returned, or merely an iterator.

These days, ‘dict.keys’, ‘dict.values’, ‘dict.items’ are re-implemented
in Python 3 as views; the same names work just fine in both Python 2 and
Python 3.

Combine that with the fact that ‘2to3’ is no longer the officially
recommended path to migrate (instead we should be aiming at the
transitional stel of Python 2 and Python 3 supported in the same code
base), and most of the advantage to the ‘dict.iter*’ recommendation is
gone.

So what we're left with is a lot of ‘dict.iter*’ added in good faith to
help porting code to Python 3, but now mostly cruft that should be
reverted to the non-‘iter*’ methods.

-- 
 \                    “It's all in the mind, you know.” —The Goon Show |
  `\                                                                   |
_o__)                                                                  |
Ben Finney


Reply to: