Answers for "dict comprehension and format in py"

2

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}
Posted by: Guest on December-29-2020
0

python dict comprehension

>>> {x: x**2 for x in (2, 4, 6)}
{2: 4, 4: 16, 6: 36}
Posted by: Guest on October-12-2021

Code answers related to "dict comprehension and format in py"

Python Answers by Framework

Browse Popular Code Answers by Language