List Comprehensions Enhancement
Greg Ewing
greg at cosc.canterbury.ac.nz
Sat Sep 11 01:31:30 EDT 1999
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:
http://www.cosc.canterbury.ac.nz/~greg/python/listcomp/index.html
--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
greg at cosc.canterbury.ac.nz
More information about the Python-list
mailing list