KnowledgeBoat Logo

Computer Science

What is a list comprehension ? How is it useful ?

Linear Lists

2 Likes

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.

Answered By

1 Like


Related Questions