Steve Howell said:But frankly, although there's no reason that you _have_ to name the
content at each step, I find it a lot more readable if you do:
tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)]
filtered = [ cube for (square, cube) in tuples if square!=25 and
for f in filtered:
print fThe names you give to the intermediate results here are
terse--"tuples" and "filtered"--so your code reads nicely.
But that example makes tuples and filtered into completely expanded
lists in memory. I don't know Ruby so I've been wondering whether the
Ruby code would run as an iterator pipeline that uses constant memory.
That's a really good question. I don't know the answer. My hunch is
that you could implement generators using Ruby syntax, but it's
probably not implemented that way.
The fact that Python allows you to turn the intermediate results into
generator expressions is a very powerful feature, of course.
might be of interest. Maybe Ruby and/or Python could grow something similar.
Can you elaborate?