© Joannah Nanjekye 2017
Joannah NanjekyePython 2 and 3 Compatibilityhttps://doi.org/10.1007/978-1-4842-2955-2_10

10. Collections and Iterators

Joannah Nanjekye
(1)
Kampala, Uganda
 
Python 3 is known to avoid returning lists and dictionaries. If k is a dictionary, in Python 2, k.keys() returns a list of the keys in the dictionary, while in Python 3, k.keys() enables iteration over the keys in something like a for loop. Similarly, k.values() and k.items() returns lists of values or key-value pairs in Python 2, while in Python 3 we can only iterate over the values in a for loop. Python 3 only contains range and it behaves like the Python 2’s xrange and in Python 3, the built-in map behaves like Python 2’s itertools.imap. Therefore in Python 2 and 3, ...

Get Python 2 and 3 Compatibility: With Six and Python-Future Libraries now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.