Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python dictionary comprehension

dict1 = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}
# Double each value in the dictionary
double_dict1 = {k:v*2 for (k,v) in dict1.items()}
# double_dict1 = {'e': 10, 'a': 2, 'c': 6, 'b': 4, 'd': 8} <-- new dict
Source by www.datacamp.com #
 
PREVIOUS NEXT
Tagged: #python #dictionary #comprehension
ADD COMMENT
Topic
Name
4+4 =