Using zip_longest on unequal lists but repeat the last entry instead of returning None
问题 There is an existing thread about this Zipping unequal lists in python in to a list which does not drop any element from longer list being zipped But it's not quite I'm after. Instead of returning None , I need it to copy the previous entry on the list. Is this possible? a = ["bottle","water","sky"] b = ["red", "blue"] for i in itertools.izip_longest(a,b): print i #result # ('bottle', 'red') # ('water', 'blue') # ('sky', None) # What I want on the third line is # ('sky', 'blue') 回答1: