Another just as cool (maybe even cooler!) yet lesser known comprehension method after list comprehension is dict comprehension.
Dict Comprehension can be used to create Python dictionaries in one line with a very cool syntax. Sometimes, dict comprehension can achieve what can normally be achieved in many lines with regular syntax. What it does is, it consolidates loops, functions, conditional statements and dictionary additions in a very compact syntax.
Dict comprehension works very similar to List comprehension however there are some differences since dictionary elements consist of 2 items which consists of “key:value” pairs.
Like many concepts in programming, dict comprehension can be explained best with a few examples and mastered best through practicing Python exercises.