Reputation: 47
I have a variable that holds lists
s=[16, 29, 16]
[16, 16, 16]
I want to combine them like this
combined = [16,16]
[29,16]
[16,16]
Upvotes: 2
Views: 58
Reputation: 239573
Use zip
function, like this
s = [[16, 29, 16], [16, 16, 16]]
print zip(*s)
# [(16, 16), (29, 16), (16, 16)]
If you want the output to be a list of lists, then you can simply do
print map(list, zip(*s))
# [[16, 16], [29, 16], [16, 16]]
Upvotes: 4