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

Cleaner way to create dictionary from zip iterables in Python

I have a lists of data, which I need to use in a function that returns a dictionary. The returned dictionary needs to be appended to a list.

dictionary_big_list = [] 

for i, j, k in zip(lst1, lst2, lst3):
     returned_dictionary = dictionary_create_function(i, j, k)
     dictionary_big_list.append(returned_dictionary)

I am looking for a cleaner way to apply the logic. The lists are the same length.

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 :

Just use map with multiple iterables:

dic_big_list = list(map(dic_create_function, list1, list2, list3))
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