input: list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
wanted output: list1 = [1, 3, 5, 7, 9], list2 = [2, 4, 6, 8, 10]
How can I do this?
input: list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
wanted output: list1 = [1, 3, 5, 7, 9], list2 = [2, 4, 6, 8, 10]
How can I do this?
You can just use slice notation with third param that is increment
values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
v1, v2 = values[::2], values[1::2]
print(v1) # [1, 3, 5, 7, 9]
print(v2) # [2, 4, 6, 8, 10]