Hello I am having a struggle with creating a python list. I have list of numbers and i want to create list of pairs so that pair is also list and it looks like this: [[x0, x1], [x1, x2], ...]
. I have tried list comprehension but its very slow for long lists.
Can anyone suggest a better (faster) solution?
example:
input = [0.74, 0.72, 0.63, 0.85, 0.75, 0.64] of length 6
output = [[0.74, 0.72], [0.72, 0.63], [0.63, 0.85], [0.85, 0.75], [0.75, 0.64]] of length 5
what i have tried:
output = [[x, y] for x, y in zip(input[0:len(input)-1], input[1:len(input)])]
Thanks in advance!!