Menu

gitpiper

to_dictionary python Code Snippet in 2022

listdictionaryintermediate

Last Updated: 26 November 2022

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.

  • Use zip() in combination with dict() to combine the values of the two lists into a dictionary.
def to_dictionary(keys, values): return dict(zip(keys, values))
to_dictionary(['a', 'b'], [1, 2]) # { a: 1, b: 2 }

python snippet similar to to_dictionary For You in November 2022

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2022 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️