Example 1: how to unzip files using zipfile module python
import zipfile
with zipfile.ZipFile("file.zip","r") as zip_ref:
zip_ref.extractall("targetdir")
Example 2: python zip function
>>> numbers = [1, 2, 3]
>>> letters = ['a', 'b', 'c']
>>> zipped = zip(numbers, letters)
>>> zipped
<zip object at 0x7fa4831153c8>
>>> type(zipped)
<class 'zip'>
>>> list(zipped)
[(1, 'a'), (2, 'b'), (3, 'c')]
Example 3: zip python
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> list(zipped)
[(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zip(x, y))
>>> x == list(x2) and y == list(y2)
True
Example 4: zip python
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> for t in zip(x, y):
... print(t)
...
(1, 4)
(2, 5)
(3, 6)
Example 5: zip python
number_list = [1, 2, 3]
str_list = ['one', 'two', 'three']
result = zip()
result_list = list(result)
print(result_list)
result = zip(number_list, str_list)
result_set = set(result)
print(result_set)
>>>[]
{(2, 'two'), (3, 'three'), (1, 'one')}
Example 6: python zip function
>>> letters = ['a', 'b', 'c']
>>> numbers = [0, 1, 2]
>>> for l, n in zip(letters, numbers):
... print(f'Letter: {l}')
... print(f'Number: {n}')
...
Letter: a
Number: 0
Letter: b
Number: 1
Letter: c
Number: 2