Python: Create a dictionary from a list of keys and values

keys = ['a', 'b', 'c']
values = [10, 20, 30]

dic = dict(zip(keys, values)) # => {'a': 10, 'b': 20, 'c': 30}

dict (iter) (ʻiteris an iterable object) is a dictionary with ʻiter [i] [0]as the key and ʻiter [i] [1] as the value for each element of ʻiter. Returns (equivalent to the code below). If len (iter [i])! = 2, then ValueError occurs.

dic = {}
for k, v in iter:
    dic[k] = v

Recommended Posts

Python: Create a dictionary from a list of keys and values
[python] Create a list of various character types
Create a dictionary in Python
How to write a list / dictionary type of Python3
[Python] Create a list of date and time (datetime type) for a certain period
Get the value of a specific key in a list from the dictionary type in the list with Python
[Python] Create a date and time list for a specified period
I compared the speed of the reference of the python in list and the reference of the dictionary comprehension made from the in list.
[Python] How to create a table from list (basic operation of table creation / change of matrix name)
Create an instance of a predefined class from a string in Python
I tried to create a list of prime numbers with python
Dig the directory and create a list of directory paths + file names
Display a list of alphabets in Python 3
Connect a lot of Python or and and
[python] Get a list of instance variables
Create a deb file from a python package
[Python] Various combinations of strings and values
[Python] Get a list of folders only
Create a decision tree from 0 with Python and understand it (5. Information Entropy)
Started Python: Swap an array of values obtained from SQL results to a list type and use it in IN of another query
[Python] List Comprehension Various ways to create a list
A memorandum of calling Python from Common Lisp
Basic operation list of Python3 list, tuple, dictionary, set
Create a New Todoist Task from Python Script
Make a copy of the list in Python
Create a web map using Python and GDAL
Create a decision tree from 0 with Python (1. Overview)
Create a datetime object from a string in Python (Python 3.3)
[Python] How to create a dictionary type list, add / change / delete elements, and extract with a for statement
List of Python code to move and remember
Create a Mac app using py2app and Python3! !!
[Python] A rough understanding of iterators, iterators, and generators
A discussion of the strengths and weaknesses of Python
Extract elements (using a list of indexes) in a NumPy style from a Python list / tuple
List of python modules
Create a Python module
Python3 List / dictionary memo
Create a Python environment
[Python] How to remove duplicate values from the list
Mayungo's Python Learning Note: List of stories and links
(Python) Treat integer values as a set of flags
List of Python libraries for data scientists and data engineers
Make a copy of a Google Drive file from Python
Receive dictionary data from a Python program in AppleScript
Summary of Python sort (list, dictionary type, Series, DataFrame)
Python points from the perspective of a C programmer
A quick comparison of Python and node.js test libraries
Create a batch of images and inflate with ImageDataGenerator
Python: Get a list of methods for an object
Group by consecutive elements of a list in Python
Display a histogram of image brightness values in python
Python script to create a JSON file from a CSV file
Create a decent shell and python environment on Windows
How to create a kubernetes pod from python code
[Python] Types of statistical values (features) and calculation methods
[Python] Start a batch file from Python and pass variables.
[Python] Sort apples and pears from pixel values using a support vector machine (SVM)
Create a Wox plugin (Python)
Create a decision tree from 0 with Python and understand it (3. Data analysis library Pandas edition)
Python list, for statement, dictionary
Create a function in Python