0 votes
in Python by
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)

Related questions

0 votes
asked Feb 11, 2021 in Python by SakshiSharma
0 votes
asked Dec 19, 2019 in Python by sharadyadav1986
...