Hacker News new | ask | show | jobs
by pdonis 5069 days ago
> The essay: http://www.paulgraham.com/progbot.html ?

Yes, that's the one I was thinking of. Thanks for finding the link!

> the mix of chained object method invocations and "outer" function calls

Actually, you're right, I could have factored out the part that builds the dict of words vs. occurrences into its own function, so that the entire pipeline would be a single chain of calls. Now that you've put the thought into my head, I may go back and do that. :-)

> I was wondering how the example script would look like using pipe[1] :-)

That would certainly make the Python look more like the shell script. :-)

One of the constraints I imposed on myself when writing the Python version was to only use what comes with it--built in functions/syntax and the standard library, with no third-party packages, similar to how McIlroy only used "built-in" Unix commands that came with every Unix system.

> One question about the Python code: is the first call to sorted needed

You're right, it isn't. I've pushed an update to the github repo fixing this (in both versions).

1 comments

> Now that you've put the thought into my head, I may go back and do that.

Just did it. :-) Factored out a "uniq" function in both versions, so the "pipeline" function is now a single chain of method invocations (with the slicing at the end). Which means it could actually be put in the "if __name__ == '__main__'" stanza, but that seems less readable to me.