Skip to content

Home

Lists to dictionary

Combines two lists into a dictionary, where the elements of the first one serve as the keys and the elements of the second one serve as the values. The values of the first list need to be unique and hashable.

def to_dictionary(keys, values):
  return dict(zip(keys, values))

to_dictionary(['a', 'b'], [1, 2]) # { a: 1, b: 2 }

More like this

Start typing a keyphrase to see matching snippets.