[Python-ideas] List Comprehensions
Chris Angelico
rosuav at gmail.com
Mon Feb 8 18:57:19 EST 2016
On Tue, Feb 9, 2016 at 10:54 AM, Michael Selik <mike at selik.org> wrote:
> I could imagine a module of fancy iterables overloading __and__ for that
> purpose, but it ought to be a large enough chunk of functionality to warrant
> a mini-language. Like NumPy. As much as I dislike the term "domain-specific
> language", I think this example of overloading operators falls into that
> category. One could take the itertools module and map all sorts of operators
> to its features:
>
> a & b ==> chain(a, b)
> it[j:k] ==> islice(it, j, k)
> +it ==> tee(it)
> a * b ==> product(a, b)
> 2-it ==> pairwise(it)
>
> etc. Not saying it's a good idea for the standard library, but I could see a
> module that makes extensive use of itertools doing so. It's worth repeating
> that I prefer using the word instead of the operator for most if not all of
> these cases.
And the cool part of it is that anyone can do this simply by creating
a class called "iter", and using that everywhere. A simple "from magic
import iter" will enable this for the people who want it AND make it
possible for everyone else to figure out what's going on.
Personally, I don't use the itertools functions anywhere near enough
to justify magic syntax, but there are people who do.
ChrisA
More information about the Python-ideas
mailing list