Python

List Comprehensions

Python supports a concept called “list comprehensions”. It can be used to construct lists in a very natural, easy way, like a mathematician is used to do.

 
1) List comprehensions provide a concise way to create lists. 
2) The list comprehension always returns a result list.
 New_list = [expression(i) for i in list if filter(i)] 

The list comprehension starts with a ‘[‘ and ‘]’, to help you remember that the
result is going to be a list.

[ expression, for item in list ,if conditional ]

Leave a comment