CBSE Class 12 Computer Science Question 36 of 68

Data Structures - I : Linear Lists — Question 8

Back to all questions
8
Question

Question 8

What is a list comprehension ? How is it useful ?

Answer

A list comprehension is a concise description of a list that shorthands the list creating for loop in the form of a single statement. The syntax is:

[expression_creating_list for (set of values to iterate upon) condition]

List comprehensions make code compact, more readable, more efficient and are faster to execute.