On Fri, Apr 9, 2021, 3:23 PM Peter Ludemann <peter.ludem...@gmail.com> wrote:
> David Mertz wrote: > > The pattern of "Create an empty collection, then add stuff in a loop" is > quite common, ... > > Or you can use comprehensions, in which case there's no need for creating > an empty collection. > > s = {f(x) for x in some_list} > Only for the very simplest cases of that pattern. Of course I use comprehensions in such cases. In many other cases, the loop that adds stuff to collections also has conditional branches to add this vs that, calls to other functions to get more data or make decisions, nested loops, temporary variables, side-effects, and so on. ... Yes, of course with enough contortions, some of that can be worked into comprehensions. But usually it is better not to, and sometimes it is impossible.
_______________________________________________ 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/CDGXTBGZPKHB4YV2IOMOYMHSSCM6FPUF/ Code of Conduct: http://python.org/psf/codeofconduct/