Make only identical pairs in python list
Solution 1:
You can use zip
and slice the input list every two items with different starting points:
lst = [1,2,3,4,5,6,7]
list(zip(lst[::2], lst[1::2]))
output: [(1, 2), (3, 4), (5, 6)]
You can use zip
and slice the input list every two items with different starting points:
lst = [1,2,3,4,5,6,7]
list(zip(lst[::2], lst[1::2]))
output: [(1, 2), (3, 4), (5, 6)]