List Comprehensions Enhancement

Greg Ewing
Thu, 23 Sep 99 05:42:01 GMT

I have implemented some of the list comprehension syntax
ideas that were discussed a while ago.

Some examples:

nums = [1, 2, 3, 4, 5]
strs = ["Apple", "Banana", "Coconut"]

print [3 * x for x in nums]
print [x for x in nums if x > 2]
print [(i, s) for i in nums for s in strs]
print [(i, s) for i in nums for s in [f for f in strs if "n" in f]]

For more details and a patch, see:

Greg Ewing, Computer Science Dept,
University of Canterbury,	  
Christchurch, New Zealand

<P><A HREF="">List
Comprehensions Patch</A> - Greg Ewing's implementation of enhanced list comprehensions
syntax for Python (using "for" and "in" keywords).  (11-Sep-99)

----------- comp.lang.python.announce (moderated) ----------
Article Submission Address:
Python Language Home Page:
Python Quick Help Index: