I think it's good to show the pythonic way.
To get an index, you can use enumerate.
If you have two lists with different sizes and want to have a default value, use itertools.zip_longest(*iterables, fillvalue=None).
zip_longest example:
It gives us one more method to format strings.
spams = [2, 4, 2, 5] eggs = [6, 4, 3, 2] for spam, egg in zip(spams, eggs): print(spam, egg)Read this: https://docs.python.org/3/library/functions.html#zip
To get an index, you can use enumerate.
If you have two lists with different sizes and want to have a default value, use itertools.zip_longest(*iterables, fillvalue=None).
zip_longest example:
from itertools import zip_longest spams = [2, 4, 2, 5, 5, 6, 7, 1, 4, 5, 6] eggs = [6, 4, 3, 2] for spam, egg in zip_longest(spams, eggs, fillvalue=1): # 1 is the neutral element in multiplication or division # 0 is the neutral element in addition or subtraction print(f"{spam} * {egg} = {spam * egg}")The f-string
f"{spam} * {egg} = {spam * egg}"
is new in Python 3.6.It gives us one more method to format strings.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!