Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.
showell30 at yahoo.com
Fri Feb 19 05:57:47 CET 2010
On Feb 18, 7:58 pm, Paul Rubin <no.em... at nospam.invalid> wrote:
> Steve Howell <showel... at yahoo.com> writes:
> >> 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:
> >> def print_numbers():
> >> 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
> >> cube!=64 ]
> >> for f in filtered:
> >> print f
> > The 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.
> > In a more real world example, the intermediate results would be
> > something like this:
> > departments
> > departments_in_new_york
> > departments_in_new_york_not_on_bonus_cycle
> > employees_in_departments_in_new_york_not_on_bonus_cycle
> > names_of_employee_in_departments_in_new_york_not_on_bonus_cycle
> might be of interest. Maybe Ruby and/or Python could grow something similar.
Can you elaborate?
More information about the Python-list