Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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'}
 
PREVIOUS NEXT
Tagged: #dictionary #comprehension #dictionary #names #list #python
ADD COMMENT
Topic
Name
6+9 =