Arbitrary and complex nested structures do seem like they would require a
complex solution. OTOH `more_itertools.flatten` seems ergonomic - and it is
very simple, just a wrapper around `itertools.chain.from_iterable` with  a
memorable name.

If that's the preferred solution, nudging users in the direction of those
functions, or a comprehension, would be useful (thinking here there should
be one-- and preferably only one --obvious way to do it). Maybe deprecation
is extreme, but what about a warning ("looks like you're trying to X maybe
you should Y")?

Adding hints might become annoying (think "Clippy the office assistant"), a
solution with added complexity would be to warn when you get to the 100th
list/tuple - so you can still sum a few lists in the REPL.

On Thu, 17 Jun 2021 at 10:46, Steven D'Aprano <st...@pearwood.info> wrote:

> On Wed, Jun 16, 2021 at 10:13:40PM -0700, Christopher Barker wrote:
>
> > If, as suggested, flattening a list of lists is a common operation, a
> nice
> > clean and efficient built in way to do it would be reasonable. Heck, you
> > could make it a list method :-)
>
> People have been talking about a flatten builtin or list method since
> Python 1.5 days. Perhaps it is time to do a PEP?
>
> Here is one example implementation from eleven years ago:
>
> https://code.activestate.com/recipes/577250-flatten-a-list/
>
>
> Start designing the API for flatten and one quickly discovers that the
> problem isn't how to implement it, but the number of options that people
> may, or may not, want. What counts as an atomic type? Flatten all the
> way down or just one level? Return a list or an iterator? Inplace or a
> new list? Etc.
>
>
>
> --
> Steve
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/6JGIEO7EXKGDISIZJ6S4FTPJ5CIPVZMP/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VUTQKJMMKIEN3VQ4XFAFKCYWW43HMXHH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to