How to make zip_longest available in itertools using Python 2.7
When trying to import this function in Python Jupyter 2.7 nb running on Windows 10, I get this error:
I believe that I have not run into problems in the past because I used Python 3. So I'm wondering if it's just not available in Python 2 or if there is a way to make it work.
If you don't know which version of Python is running the script, you can use this trick:
try:
from itertools import zip_longest
except ImportError:
from itertools import izip_longest as zip_longest
# now this works in both python 2 and 3
print(list(zip_longest([1,2,3],[4,5])))