Python Lambda List Comprehension
List Comprehensions
- At a most basic level, Python lists are collections of data. However, Python makes list such fundemental data types that may operations and functions exist that work exclusively on lists. One of these operations is the list comprehension, where a programmer can create a list through selection from another list. In this example, a programmer creates a list ("l2") by multiplying all the elements from list one ("l1"):
>>>l1 = [1, 2, 3]
>>>l2 = [2*x for x in l1]
>>>l2
[2, 4, 6]
Source...