martedì 27 aprile 2010

List comprehension

Hello guys!

I've found a new way to make a list.

Before that discovery, to create a new list, I made
#python code
list=[]
for i in range(0, 5):
....list.append(i)

Now, with "List comprehension", I can make it in a single line:
#python code
list=[i for i in range(0, 5)]

List comprehension helps you to create a list in a very quickly way!

Another helps:
wiki page on list comprehension
python docs about list comprehension