Problem Statement
Explain dictionary comprehension and one practical use case.
Explanation
Dictionary comprehension builds a mapping in a single readable expression. It iterates a source and computes key and value pairs on the fly.
A common use is transforming a list into a lookup table or filtering an existing dict by a condition. It keeps code concise and avoids multi-step loops and temporary variables.
Code Solution
SolutionRead Only
names=['a','bb','ccc']
lengths={n:len(n) for n in names if len(n)>1}