Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82766

Re: List Comprehensions

References <mailman.17108.1419226965.18130.python-list@python.org> <5497e2a2$0$12978$c3e8da3$5496439d@news.astraweb.com>
Date 2014-12-22 20:45 +1100
Subject Re: List Comprehensions
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.17116.1419241532.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Dec 22, 2014 at 8:21 PM, Steven D'Aprano
<steve+comp.lang.python@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

List Comprehensions Ganesh Pal <ganesh1pal@gmail.com> - 2014-12-22 11:12 +0530
  Re: List Comprehensions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-22 20:21 +1100
    Re: List Comprehensions Chris Angelico <rosuav@gmail.com> - 2014-12-22 20:45 +1100
      Re: List Comprehensions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-23 02:18 +1100
        Re: List Comprehensions Chris Angelico <rosuav@gmail.com> - 2014-12-23 04:10 +1100
        Re: List Comprehensions Terry Reedy <tjreedy@udel.edu> - 2014-12-22 15:28 -0500
    Re: List Comprehensions Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-22 08:12 -0700

csiph-web