Reputation: 15
Recently I have multiple lists in Python but don know how integrate in new one:
For example below:
ids = ['a','b','c','d','e']
p = [0.01, 0.02, 0.07, 0.04, 0.09]
qty = [10, 30, 50, 70, 90]
The desire result should be below:
combine =
[a, 0.01, 10]
[b, 0.02, 30]
[c, 0.07, 50]
[d, 0.04, 70]
[e, 0.09, 90]
Upvotes: 0
Views: 42
Reputation: 744
This is what the zip()
operator is for:
>>> ids = ['a','b','c','d','e']
>>> p = [0.01, 0.02, 0.07, 0.04, 0.09]
>>> qty = [10, 30, 50, 70, 90]
>>> combine = list(zip(ids, p, qty))
>>> combine
[
('a', 0.01, 10),
('b', 0.02, 30),
('c', 0.07, 50),
('d', 0.04, 70),
('e', 0.09, 90)
]
Upvotes: 3