-
四季花海
print map(None, *([iter([1,2,3,4,5])] * 2))#[(1, 2), (3, 4), (5, None)]print map(None, *([iter([1])] * 2))#[(1, None)]
-
月关宝盒
list(dict(zip(demo[::2], demo[1::2] if len(demo)%2==0 else demo.append(None))).items())还是分2行吧
demo if len(demo)%2 == 0 else demo.append(None)
list(dict(zip(demo[::2],demo[1::2])).items())
-
慕少森
demo = [1, 2, 3, 4, 5]
print(map(None, demo[::2], demo[1::2]))
-
守候你守候我
python3
>>> from itertools import zip_longest as zipl
>>> list(zipl(*([iter([1,2,3,4,5])] * 2)))
[(1, 2), (3, 4), (5, None)]
>>> list(zipl(*([iter([1])] * 2)))
[(1, None)]