List Comprehension : List Comprehension « List « Python Tutorial






print [x*x for x in range(10)] 

print [x*x for x in range(10) if x % 3 == 0] 
print [(x, y) for x in range(3) for y in range(3)]

li = [1, 9, 8, 4] 
print [elem*2 for elem in li]                   
print li                                             
li = [elem*2 for elem in li]                  
print li








7.15.List Comprehension
7.15.1.List Comprehension
7.15.2.List Comprehensions in build Connection String, Step by Step
7.15.3.Filtering Lists: [mapping-expression for element in source-list if filter-expression]
7.15.4.List Type Operators and List Comprehensions
7.15.5.Extended List Comprehension Syntax
7.15.6.Using List Comprehensions on Files