I use the zip like this
list1 = ['a', 'b', 'c', 'd']
list2 = [1, 2, 3, 4]
result = zip(list1, list2) #[('a', 1), ('b', 2), ('c', 3), ('d', 4)]
The opposite of the zip
[('a', 1), ('b', 2), ('c', 3), ('d', 4)]
(['a', 'b', 'c', 'd'], [1, 2, 3, 4])
How can I change it?
Use the *
operator to decompose the zip.
myzip = [('a', 1), ('b', 2), ('c', 3), ('d', 4)]
list1, list2 = zip(*myzip)
#list1, list2 = same as zip (('a', 1), ('b', 2), ('c', 3), ('d', 4))
print list1
print list2
Output:
('a', 'b', 'c', 'd')
(1, 2, 3, 4)
© 2024 OneMinuteCode. All rights reserved.