Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58926
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'forgive': 0.05; 'args': 0.07; 'subject:code': 0.07; 'preferable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; "wouldn't": 0.14; 'args,': 0.16; 'clear.': 0.16; 'lambda': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'sequence.': 0.16; 'starmap': 0.16; 'language': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'code.': 0.18; 'library': 0.18; 'bit': 0.19; 'machine': 0.22; 'example': 0.22; 'saying': 0.22; 'header:User-Agent:1': 0.23; 'options': 0.25; 'developing': 0.27; 'header:X-Complaints- To:1': 0.27; 'point': 0.28; 'function': 0.29; "i'm": 0.30; '>>>>': 0.31; 'closer': 0.31; 'coded': 0.31; 'concise': 0.31; "skip:' 40": 0.31; 'skip:c 30': 0.32; 'quite': 0.32; 'continuing': 0.33; 'could': 0.34; 'problem': 0.35; 'but': 0.35; 'there': 0.35; 'explains': 0.36; 'should': 0.36; 'sometimes': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'letters': 0.60; 'no.': 0.61; 'map': 0.64; 'pick': 0.64; 'more': 0.64; 'said:': 0.68; 'obvious': 0.74; 'otten': 0.84; 'same,': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: my favorite line of py code so far |
| Date | Sat, 09 Nov 2013 12:49:35 +0100 |
| Organization | None |
| References | <fbbabb45-f0e3-4e7f-968f-9822607c450a@googlegroups.com> <729e093a-6312-44dc-8ed4-1dd5ea344066@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p5084bb2a.dip0.t-ipconnect.de |
| User-Agent | KNode/4.7.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2288.1383997830.18130.python-list@python.org> (permalink) |
| Lines | 64 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1383997830 news.xs4all.nl 15883 [2001:888:2000:d::a6]:52568 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:58926 |
Show key headers only | View raw
Peter Cacioppi wrote:
> Peter Otten said:
>
>
> ">>> _ = lambda c: lambda x: c(*x)
>>>> list(map(_(P), zip([1,2,3], [6, 5, 4])))
> [Point(x=1, y=6), Point(x=2, y=5), Point(x=3, y=4)]
>
> ? While the obvious approach would be
>
>>>> [P(*args) for args in zip([1,2,3], [6, 5, 4])]
> [Point(x=1, y=6), Point(x=2, y=5), Point(x=3, y=4)] "
>
> I would have coded
>>>> map(_(P), zip([1,2,3], [6, 5, 4]))
>
> Which is very concise and (to me) quite clear. Forgive me for having a
> bias for fewer characters.
Consider developing a bias for self-explanatory names ;)
> Are you saying it's always preferable to avoid map?
No. I'm saying that if you have a problem with multiple solutions you should
pick the boringly obvious one if you plan to reuse or publish the code.
There is no obvious meaning attached to _ -- so don't use it.
> Is map going to be deprecated?
Not to my knowledge. I use it when I already have a function ready
to be called with the items in a sequence. Continuing the Point example that
could be
map(Point, xvals, yvals)
or
map(Point.from_tuple, xypairs)
> I sometimes use map, sometimes comprehensions. I suspect other people do
> the same, that's why the language supports map and comprehensions.
>
> "there is also itertools.starmap(): "
>
> Thanks, that's a bit closer to what I am doing. To me the pure combinator
> is more appealing than starmap, but the presence of starmap explains why
> the library wouldn't need the combinator.
I found only a single use of starmap on my machine (and one more in the
stdlib)
# in redis.client
all_cmds = ''.join(starmap(connection.pack_command,
[args for args, options in commands]))
and frankly, I would prefer
all_cmds = "".join(
connection.pack_command(*args) for args, options in commands)
which by some strange coincidence also requires fewer letters to type.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
my favorite line of py code so far Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-11-08 14:22 -0800
Re: my favorite line of py code so far Chris Angelico <rosuav@gmail.com> - 2013-11-09 09:32 +1100
Re: my favorite line of py code so far Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-11-08 14:43 -0800
Re: my favorite line of py code so far Peter Otten <__peter__@web.de> - 2013-11-09 08:12 +0100
Re: my favorite line of py code so far Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-11-09 01:23 -0800
Re: my favorite line of py code so far Chris Angelico <rosuav@gmail.com> - 2013-11-09 20:28 +1100
Re: my favorite line of py code so far Paul Rubin <no.email@nospam.invalid> - 2013-11-09 01:49 -0800
Re: my favorite line of py code so far Peter Otten <__peter__@web.de> - 2013-11-09 12:49 +0100
Re: my favorite line of py code so far Stefan Behnel <stefan_ml@behnel.de> - 2013-11-09 13:41 +0100
Re: my favorite line of py code so far Chris Angelico <rosuav@gmail.com> - 2013-11-09 23:45 +1100
Re: my favorite line of py code so far Peter Otten <__peter__@web.de> - 2013-11-09 14:49 +0100
Re: my favorite line of py code so far Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-11-10 00:57 -0800
Re: my favorite line of py code so far Chris Angelico <rosuav@gmail.com> - 2013-11-10 21:23 +1100
Re: my favorite line of py code so far Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-11-10 00:59 -0800
Re: my favorite line of py code so far Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-11-10 16:00 -0800
csiph-web