Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to use dictionary comprehension to make a dictionary for some names of a list in python

names = ["David", "Sarah", "Matt"]

# it makes name as key and Doctor as value for each name in list names
career = {name:"Doctor" for name in names} 

print(career)

#output >>> {'David': 'Doctor', 'Sarah': 'Doctor', 'Matt': 'Doctor'}
Comment

PREVIOUS NEXT
Code Example
Python :: python make file path os 
Python :: python gui using css 
Python :: how to open xml file element tree 
Python :: python make sound when finished 
Python :: turn off xticks matplotlib 
Python :: sum of positive numbers in array with negative python 
Python :: dataframe groupby multiple columns 
Python :: what is the use of class in python 
Python :: dictionary to a dataframe pandas arrays must all be same length 
Python :: flatten a 2d list 
Python :: Count NaN values of an DataFrame 
Python :: keras.layers.MaxPool2D 
Python :: keras tuner 
Python :: modify string in column pandas 
Python :: renaming column in dataframe pandas 
Python :: python with statement file does not exist exception 
Python :: python creating a dict from a string 
Python :: pycairo 
Python :: swapping of two numbers in python 
Python :: mac catallina python3 
Python :: Make a Basic Face Detection Algorithm in Python Using OpenCV and Haar Cascades 
Python :: how to distribute a dataset in train and test using scikit 
Python :: how to sum only the even values in python 
Python :: pandas create a calculated column 
Python :: get last element of a list python 
Python :: list sort by key python 
Python :: get sum of a range from user input 
Python :: import error in same directory python 
Python :: remove duplicates function python 
Python :: time.sleep() faster 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =