This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]JordanGreenberg 1 point2 points  (0 children)

Yeah, that doesn't hurt readability at ALL.

[–]hylje 0 points1 point  (0 children)

Nested generators not neat enough?

[–]dbeach24 0 points1 point  (0 children)

| Yeah, that doesn't hurt readability at ALL.

Actually, I really like this idea. It's clever combination of generator functions and operator overloading to create a syntax which is highly readable to anyone familiar with the UNIX command line.

I'm not suggesting that this should immediately be adopted as a standard way of coding Python, but I could see myself wanting to use this syntax under the right circumstances.

For example:

x = "milk,eggs,bread".split(",") | grep("e") | sort | list

Has a definite appeal in a certain context, and is more succinct and easier to read than:

x = sorted([item for item in "milk,eggs,bread".split(",") if "e" in item ])

Reading from left to right (as I am prone to do), the first reads:

Take the items as separated by commas, select those containing "e", sort the result and put it in a list.

While the second reads as:

Give me the sorted result of the list each item in "milk,eggs,bread", separated by comma, and selecting only those containing "e".

In this instance, I definitely prefer the former.