Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #84662
| From | Neal Becker <ndbecker2@gmail.com> |
|---|---|
| Subject | Re: Is there a more elegant way to spell this? |
| Date | 2015-01-27 13:25 -0500 |
| References | <mailman.18170.1422364524.18130.python-list@python.org> <qot7fw8s3la.fsf@ruuvi.it.helsinki.fi> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18182.1422383167.18130.python-list@python.org> (permalink) |
Jussi Piitulainen wrote: > Neal Becker writes: > >> Is there a more elegant way to spell this? >> >> for x in [_ for _ in seq if some_predicate]: > > If you mean some_predicate(_), then possibly this. > > for x in filter(some_predicate, seq): > handle(x) > > If you mean literally some_predicate, then perhaps this. > > if some_predicate: > for x in seq: > handle(x) > > Unless you also have in mind an interesting arrangement where > some_predicate might change during the loop, like this. > > for x in [_ for _ in seq if some_predicate]: > ... > some_predicate = fubar(x) > ... > > Then I have nothing to say. To clarify, I meant some_predicate(_), and then ifilter looks like a nice solution. -- -- Those who don't understand recursion are doomed to repeat it
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is there a more elegant way to spell this? Neal Becker <ndbecker2@gmail.com> - 2015-01-27 08:15 -0500
Re: Is there a more elegant way to spell this? Rustom Mody <rustompmody@gmail.com> - 2015-01-27 06:08 -0800
Re: Is there a more elegant way to spell this? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-01-27 16:25 +0200
Re: Is there a more elegant way to spell this? Neal Becker <ndbecker2@gmail.com> - 2015-01-27 09:37 -0500
Re: Is there a more elegant way to spell this? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-01-27 16:47 +0200
Re: Is there a more elegant way to spell this? Mario Figueiredo <marfig@gmail.com> - 2015-01-27 19:05 +0100
Re: Is there a more elegant way to spell this? random832@fastmail.us - 2015-01-27 13:13 -0500
Re: Is there a more elegant way to spell this? Neal Becker <ndbecker2@gmail.com> - 2015-01-27 13:25 -0500
Re: Is there a more elegant way to spell this? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-28 11:55 +1100
Re: Is there a more elegant way to spell this? Mario Figueiredo <marfig@gmail.com> - 2015-01-28 02:19 +0100
Re: Is there a more elegant way to spell this? Ben Finney <ben+python@benfinney.id.au> - 2015-01-28 12:29 +1100
Re: Is there a more elegant way to spell this? Mario Figueiredo <marfig@gmail.com> - 2015-01-28 09:32 +0100
Re: Is there a more elegant way to spell this? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-28 13:16 +1100
csiph-web