Like this:
keys = ['a', 'b', 'c']
values = [1, 2, 3]
dictionary = dict(zip(keys, values))
print(dictionary) # {'a': 1, 'b': 2, 'c': 3}
Voila đŸ™‚ The pairwise dict
constructor and zip
function are awesomely useful.
More Related Contents:
- How do I sort a list of dictionaries by a value of the dictionary?
- Access nested dictionary items via a list of keys?
- Why can’t I use a list as a dict key in python?
- How can I get list of values from dict?
- How do I merge a list of dicts into a single dict?
- Grouping Python dictionary keys as a list and create a new dictionary with this list as a value
- Getting a list of values from a list of dicts
- How do I initialize a dictionary of empty lists in Python?
- Pandas DataFrame to List of Dictionaries
- Creating a list of dictionaries results in a list of copies of the same dictionary
- python filter list of dictionaries based on key value
- How can I make a dictionary from separate lists of keys and values?
- How to convert list of key-value tuples into dictionary?
- Merging dictionary value lists in python
- join two lists of dictionaries on a single key
- Check if value already exists within list of dictionaries?
- Convert list into a dictionary [duplicate]
- Combining Dictionaries Of Lists In Python
- Most Pythonic Way to Build Dictionary From Single List
- Python – sum values in dictionary
- Setting a value in a nested Python dictionary given a list of indices and value
- Python: get a dict from a list based on something inside the dict
- How can I avoid “RuntimeError: dictionary changed size during iteration” error?
- Changing one dict changes all dicts in a list of dicts [duplicate]
- Appending to list in Python dictionary [duplicate]
- Mapping dictionary value to list
- How to sort a list of dictionaries by a value of the dictionary in Python?
- How to extract all values from a dictionary in Python?
- Comparing 2 lists consisting of dictionaries with unique keys in python
- How to create a nested dictionary from a list in Python?