Reputation: 7
Hello I have a quick question I cant seem to solve.
I have a list:
a = [item1, item2, item3, item4, item5, item6]
And I want to split this list into two seperate ones by everything other item such that:
b = [item1, item3, item5]
c = [item2, item4, item6]
Upvotes: 1
Views: 334
Reputation: 12092
Using filter is one option:
a = [item1, item2, item3, item4, item5, item6]
b = filter(lambda x: a.index(x) % 2 == 0, a)
c = filter(lambda x: a.index(x) % 2 != 0, a)
EDIT: This would require for the elements to be unique and is inefficient.
Upvotes: 0