The following code behaves differently in Python 2 vs Python 3:
all(map(lambda x,y: x, [1, 2], [1, 2, 3]))
Python 2 gives False
whereas Python 3 gives True
. The documentation for Python 2 says that it will supply None
if the shorter list is exhausted but Python 3 doesn't do that.
I am working on a code that really needs the length to be maintained for some reason. What is the cleanest way to get the old behavior? I know I can use from past.builtin import map as old_map
, but is there a more elegant solution that would work in both versions?