Home > OS >  Cleaner way to create dictionary from zip iterables in Python
Cleaner way to create dictionary from zip iterables in Python

Time:11-16

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.

CodePudding user response:

Just use map with multiple iterables:

dic_big_list = list(map(dic_create_function, list1, list2, list3))
  • Related