SyntaxFix
Write A Post
Hire A Developer
Questions
There are many ways to do that. For example:
lst = [1,2,3,4,5,6] [(lst[i], lst[i+1]) for i,_ in enumerate(lst[:-1])] >>>[(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)] [i for i in zip(*[iter(lst)]*2)] >>>[(1, 2), (3, 4), (5, 6)]