-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14_zip.py
More file actions
27 lines (17 loc) · 847 Bytes
/
14_zip.py
File metadata and controls
27 lines (17 loc) · 847 Bytes
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
first_name = ['Joe','Earnst','Thomas','Martin','Charles']
last_name = ['Schmoe','Ehlmann','Fischer','Walter','Rogan','Green']
age = [23, 65, 11, 36, 83]
print(list(zip(first_name,last_name, age)))
# Unzip
# We can use the zip function to unzip a list as well. This time, we need an input of a list with an asterisk before it.
full_name_list = [('Joe', 'Schmoe', 23),
('Earnst', 'Ehlmann', 65),
('Thomas', 'Fischer', 11),
('Martin', 'Walter', 36),
('Charles', 'Rogan', 83)]
first_name, last_name, age = list(zip(*full_name_list))
print(f"first name: {first_name}\nlast name: {last_name} \nage: {age}")
# Output
# first name: ('Joe', 'Earnst', 'Thomas', 'Martin', 'Charles')
# last name: ('Schmoe', 'Ehlmann', 'Fischer', 'Walter', 'Rogan')
# age: (23, 65, 11, 36, 83)