Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

dict comprehension python

# dict comprehension we use same logic, with a difference of key:value pair
# {key:value for i in list}

fruits = ["apple", "banana", "cherry"]
print({f: len(f) for f in fruits})

#output
{'apple': 5, 'banana': 6, 'cherry': 6}
Source by www.datacamp.com #
 
PREVIOUS NEXT
Tagged: #dict #comprehension #python
ADD COMMENT
Topic
Name
8+8 =