38. Python zip and unzip
1. Basic Usage of zip
ziplist1 = [1, 2, 3]
list2 = ['a', 'b', 'c']
zipped = zip(list1, list2)
zipped_list = list(zipped)
print(zipped_list)
# Output: [(1, 'a'), (2, 'b'), (3, 'c')]2. Unzipping with zip and *
zip and *zipped_list = [(1, 'a'), (2, 'b'), (3, 'c')]
unzipped = zip(*zipped_list)
list1, list2 = list(unzipped)
print(list1) # Output: [1, 2, 3]
print(list2) # Output: ['a', 'b', 'c']3. Zipping Multiple Iterables
4. Zipping with Different Lengths
5. Using zip with Dictionaries
zip with Dictionaries6. Zipping and Unzipping with Iterables of Unequal Lengths
7. Unzipping and Repacking
8. Unpacking with * to Pass Arguments
* to Pass Arguments9. Zipping with a Custom Function
10. Zipping and Iterating with Indices
Last updated