How do I combine one input to a list of another input in order?

Say I had an input of:

john bob alex liam # names
15 17 16 19 # age
70 92 70 100 # iq

How do I make it so that john is assigned to age 15 and iq of 70, bob is assigned to age 17 and iq of 92, alex is assigned to age 16 and iq of 70, and liam is assigned to age 19 and iq of 100?

Right now I have:

names = input().split()

From there, I know have to make 2 more variables for age and iq and assign them to inputs as well but how do I assign those numbers to the names in the same order?

>Solution :

We can form 3 lists and then zip them together:

names = "john bob alex liam"
ages = "15 17 16 19"
iq = "70 92 70 100"
list_a = names.split()
list_b = ages.split()
list_c = iq.split()
zipped = zip(list_a, list_b, list_c)
zipped_list = list(zipped)  

print(zipped_list)

This prints:

[('john', '15', '70'), ('bob', '17', '92'), ('alex', '16', '70'), ('liam', '19', '100')]

Leave a Reply