swisscheese_95
swisscheese_95

Reputation: 25

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.

Upvotes: 1

Views: 55

Answers (1)

user2390182
user2390182

Reputation: 73460

Just use map with multiple iterables:

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

Upvotes: 3

Related Questions