Convert two lists into a dictionary

PHOTO EMBED

Tue Apr 21 2020 11:45:29 GMT+0000 (Coordinated Universal Time)

Saved by @TrickyMind #python #python #lists #dictionary

keys, values)) # {'a': 2, 'c': 4, 'b': 3}
 
 
#make a function: def is the keyword for the function:
def to_dictionary(keys, values):
 
 
#return is the keyword that tells program that function has to return value   
return dict(zip(keys, values))
 
  
 
# keys and values are the lists:
 
keys = ["a", "b", "c"]   
 
values = [2, 3, 4]
                                
                                
content_copyCOPY

This code is used to convert two lists into a dictionary.

https://towardsdatascience.com/30-helpful-python-snippets-that-you-can-learn-in-30-seconds-or-less-69bb49204172