# Tagged: list

# Python: List Comprehensions

Nature and life are one and the same. Programmatic nature is innate. Example, mathematical concepts translated into coded constructs such as list comprehensions in Python: http://www.secnetix.de/olli/Python/list_comprehensions.hawk http://www.codecademy.com/groups/python-fro-beginners/discussions/50cf63f7bc3b636c4500001d My favorite example from list comprehension is the usage of creating a primes list: `>>> `

`noprimes = [j for i in range(2, 8) for j in range(i*2, 50, i)]`

`>>> `

`primes = [x for x in range(2, 50) if x not in noprimes]`

`>>> `

`print primes`

`[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]` |

Advertisements