Liam Clarke wrote:
Is there any guides to this (possibly obtuse) tool?


Think of it this way. A list comprehension generates a new list. So, you should think about list comps whenever you have old_list -> new_list style behavior.


There are two advantages to list comps over map:

1) a list comp can use a predicate to filter results

[ x for x in mylist if is Prime(x) ] for instance. that would be map(lambda x: x, filter(isPrime, mylist)) which is a little more dense.

2) usually there is no need for a lambda. Not that there is anything wrong with lambdas mind you (-:

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to