Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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')]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading