in Python by
Q:
What Is The Syntax For Dictionary Comprehension In Python?

1 Answer

0 votes
by
A dictionary has the same syntax as was for the list comprehension but the difference is that it uses curly braces:

{ aKey, itsValue for aKey in iterable }

For example, the below code will return all the numbers 10 to 20 as the keys and will store the respective squares of those numbers as the values.

>>> adict = {var:var**2 for var in range(10, 20)}

>>> print(adict)
Click here to read more about Python
Click here to read more about Insurance

Related questions

0 votes
asked Aug 30, 2020 in Python by sharadyadav1986
0 votes
asked Jan 10 in Python by rajeshsharma
...