You can safely ignore this "extra precautions" warning: your code will work the same even without list
in both versions of Python. It would run differently if you needed a list (but this is not the case): in fact, features.items()
is a list in Python 2, but a view in Python 3. They work the same when used as an iterable, as in your example.
Now, the Python 2 to Python 3 conversion tool 2to3
errs on the side of safety, and assumes that you really wanted a list when you use dict.items()
. This may not be the case (as in the question), in which case dict.items()
in Python 3 (no wrapping list
) is better (faster, and less memory-consuming, since no list is built).
Concretely, this means that Python 2 code can explicitly iterate over the view: for k, v in features.viewitems()
(which will be converted in Python 3 by 2to3
to features.items()
). It looks like your IDE thinks that the code is Python 2, because your for
statement is very good, in Python 3, so there should be no warning about Python 3 support.
'{}={}'.format(k, v)
is recommended instead. :) Reference: docs.python.org/3.0/whatsnew/… – Manganate