List Comprehensions

Chris Angelico rosuav at gmail.com
Mon Dec 22 04:45:29 EST 2014


On Mon, Dec 22, 2014 at 8:21 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> If the called function has side-effects, a list comp is not a good solution.

Hmm. I'm not so sure about that. Side effects are fine in a list comp,
as long as you're making use of the return values. For instance, if
you have a function that inserts a record to a database and returns
the new ID, you could reasonably use a list comp to save a bunch of
records and get a list of IDs for subsequent use.

ChrisA



More information about the Python-list mailing list