On Tue, Jul 03, 2018 at 04:12:14PM +0200, Nicolas Rolin wrote:

> I agree the examples have lisp-level of brackets. However by using the fact
> tuples don't need brackets and the fact we can use a list instead of an
> iterable (the grouper will have to stock the whole object in memory anyway,
> and if it is really big, use itertools.groupby who is designed exactly for
> that)
> For example
> grouping(((len(word), word) for word in words))
> can be written
> grouping([len(word), word for word in words])
> 
> which is less "bracket issue prone".

Did you try this? It is a syntax error. Generator expressions must be 
surrounded by round brackets:

    grouping([len(word), (word for word in words)])

Or perhaps you meant this:

    grouping([(len(word), word) for word in words])

but now it seems pointless to use a list comprehension instead of a 
generator expression:

    grouping((len(word), word) for word in words)

but why are we using key values by hand when grouping ought to do it for 
us, as Michael Selik's version does?

    grouping(words, key=len)



-- 
Steve
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to