Convert list into list of tuples of every two elements
Fun with iter
:
it = iter(l)
[*zip(it, it)] # list(zip(it, it))
# [(0, 1), (2, 3), (4, 5)]
You can also slice in strides of 2 and zip
:
[*zip(l[::2], l[1::2]))]
# [(0, 1), (2, 3), (4, 5)]
You can also do this with list comprehension without zip
l=[0, 1, 2, 3, 4, 5]
print([(l[i],l[i+1]) for i in range(0,len(l),2)])
#[(0, 1), (2, 3), (4, 5)]