Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61387
| References | <mailman.3674.1386374070.18130.python-list@python.org> <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com> <CAGGBd_q3rQSY=5p0DjqTC5327Kap-hDvVA8V1V_D12avp-fM3A@mail.gmail.com> <l84hp4$nh$1@ger.gmane.org> |
|---|---|
| Date | 2013-12-10 00:59 +1100 |
| Subject | Re: One liners |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3779.1386597567.18130.python-list@python.org> (permalink) |
On Tue, Dec 10, 2013 at 12:49 AM, Neil Cerutti <neilc@norwich.edu> wrote:
> names = (p.name for p in db.query_people() if p.total_purchases > 0)
> names = (n.upper() for n in names)
> names = (n for n in names if not n.startswith("Q"))
> for n in names:
> # Finally actually do something.
>
> Coincidentally it's a nice way to break up an ugly one-liner. I
> also really like that if I choose to no longer filter out
> customers whose name begins with Q, I can just comment out that
> one line. Try doing that with the one-liner version!
# With the restriction:
for n in (p.name.upper() for n in names if not n.startswith("Q")):
# Without the restriction:
for n in (p.name.upper() for n in names ):# if not n.startswith("Q")):
You just have to use the special "comment-out-partially" operator,
which looks like "):#" and is inspired by some kind of insane smiley
with weird hair.
ChrisA
(Anyone got the cheek de-tonguer handy?)
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
One liners Dan Stromberg <drsalists@gmail.com> - 2013-12-06 15:54 -0800
Re: One liners Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-07 02:07 +0000
Re: One liners Dan Stromberg <drsalists@gmail.com> - 2013-12-06 19:20 -0800
Re: One liners Roy Smith <roy@panix.com> - 2013-12-06 22:53 -0500
Re: One liners Steven D'Aprano <steve@pearwood.info> - 2013-12-10 03:36 +0000
Re: One liners Neil Cerutti <neilc@norwich.edu> - 2013-12-09 13:49 +0000
Re: One liners Chris Angelico <rosuav@gmail.com> - 2013-12-10 00:59 +1100
csiph-web