Suggesting a new feature - "Inverse Generators"

Jordan Rastrick jrastrick at student.usyd.edu.au
Fri Mar 25 18:23:01 CET 2005


Wow, if I'm going to get replies (with implemented solutions!) this
quickly, I'll post here more often :-)

This is the most different to my solution, and also the shortest, and
therefore the most interesting, reply so far. Its also the last one
I'll reply to before I go to bed. zzzz....

Its taken me a while to get a rough understanding of this code, but I
think I have some idea. Correct me if I'm wrong.

groupby groups based on value of line(record)

Record returns 1 for the first line, 1 of the second, 1 for the 3rd,
then 2 for the 4th because seq[0] gets incremented since len(line) > 20

OK thats fair enough. But how does record retain state between calls?
How is that related to the fact your storing your value as a singleton
list, instead just an int?

It seems a little confusing to be honest, probably mainly due to my
unfamiliarity with groupby. Retaining state between method calls is
part of what interests me so much about the Generator/ Acceptor case.
Here youre retaining state between calls with none of the special
syntax used for example in Generators.

How? Is it a side effect of the way groupby uses record? If so, then
thats a littleoblique and unreadable for my liking.

Is the state the record returns passed back to it somehow? I take it
gets passed a value for seq at some point, seeing as how you've
bothered to define it as a default argument rather than just seq = [0]
on the first line.

That works, but at the cost of having to return and pass all of state
every call. I imagine other solutions (Generator/Acceptor based etc)
would be substanitally more efficient. And again more readable, to a
Python beginner such as myself at least.

Still, this is fascinating.... going to have to spend some time
experimenting with groupby as soon as I get a chance....




More information about the Python-list mailing list