-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip.py
36 lines (26 loc) · 770 Bytes
/
zip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'''
zip() function works kind of like a combiner of collections.
syntax: zip(iterable1, iterable2[, iterable3, iterable4, ...])
'''
# Example of zip:
my_list = [1, 2, 3]
your_list = [10, 20, 30]
their_list = [5, 4, 3]
tuple_list = (10, 20, 30)
print(list(zip(my_list, your_list)))
print(list(zip(my_list, tuple_list)))
print(list(zip(my_list, your_list, their_list)))
'''
The zip() function in the first look may note seem useful, but
it's use is when we pick data from a database into lists.
To combine those lists into a single list of tuples which
inturn replicate a database table, is a really powerful
feature of the zip() function.
'''
'''
Output:
------
[(1, 10), (2, 20), (3, 30)]
[(1, 10), (2, 20), (3, 30)]
[(1, 10, 5), (2, 20, 4), (3, 30, 3)]
'''