> Still got a question. This notation/syntax of the list:
>
> [ item for i, item in data if i in columns ]
>
> is quite new for me. Can someone point me to more examples of this
use
> Or give me the name of it (it must have a name) so i can google it?

Its a list comprehension, and theres a short explanation
of them in the functional programming topic of my tutor.

But there is one twist in this one, the comma after i:

item for i,item in data...

that makes the i,item a tuple. Normally we see a single thing there:

[n for n in list]

But if the list is a list of pairs(tuples) we can unpack the
tuple into the two names:

L = [(1,2),(3,4),(5,6)]

print [i for i,j in L]

should print

[1,3,5]

The first element of each tuple.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to