12 Comprehensions in Python

We have seen few comprehension examples while studying list and dictionary datatypes. Now we can see it in detail as we have also studied for loop. There are two types of comprehensions in python.

  1. List Comprehension

  2. Dictionary Comprehension

  • Comprehensions are optimised single line for loop expressions used inside lists and dictionaries.

  • Comprehensions are used to obtain the desired list or dictionary from existing list or dictionary.

  • List comprehension always provides output in list form.

  • Dictionary comprehension always provides output in dictionary form.