List Comprehensions


In [9]:
numbers = list(range(65, 75))
print numbers


[65, 66, 67, 68, 69, 70, 71, 72, 73, 74]

In [10]:
# with a loop
letters = []
for n in numbers:
    letters.append(chr(n))
print letters


['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']

In [11]:
# list comprehension
print [chr(n) for n in numbers]


['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']