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

Using zip to create a dictionary doesn't result in a dictionary of the same length when list items repeat

Zipping does not do what I thought, it seems to drop items.

names = ['nik', 'katie', 'james', "katie"]
ages = [32, 31, 34, 106]
my_dict = dict(zip(names, ages))
print(my_dict)

This gives:

{'nik': 32, 'katie': 106, 'james': 34}

Where did my younger Katie go? And how do I use zip to create a dictionary that keeps my original list length and doesn’t drop any items?

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

>Solution :

Python dictionary cannot have two same keys

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