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


Groups > comp.lang.python > #9510 > unrolled thread

Re: Please critique my script

Started byChris Angelico <rosuav@gmail.com>
First post2011-07-15 16:36 +1000
Last post2011-07-15 17:57 +1000
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Please critique my script Chris Angelico <rosuav@gmail.com> - 2011-07-15 16:36 +1000
    Re: Please critique my script "bruno.desthuilliers@gmail.com" <bruno.desthuilliers@gmail.com> - 2011-07-15 00:19 -0700
      Re: Please critique my script Chris Angelico <rosuav@gmail.com> - 2011-07-15 17:57 +1000

#9510 — Re: Please critique my script

FromChris Angelico <rosuav@gmail.com>
Date2011-07-15 16:36 +1000
SubjectRe: Please critique my script
Message-ID<mailman.1047.1310711795.1164.python-list@python.org>
On Fri, Jul 15, 2011 at 4:03 AM, Ellerbee, Edward <EEllerbee@bbandt.com> wrote:
> for makenewlist in range(0,count):
>     sortlist.append(npalist.pop(0) + nxxlist.pop(0))

This can alternatively be done with map():

sortlist = map(lambda x,y: x+y, npalist, nxxlist)

However, I'm not sure what your code is meant to do if the two lists
have differing numbers of elements (if the two regexps turn up
differing numbers of results). If you can assume that this won't
happen, the simple map call will do the job.

(It would have been a lot cleaner if Python exposed its operators as
functions. In Pike, that lambda would simply be `+ (backtick-plus).)

Chris Angelico

[toc] | [next] | [standalone]


#9512

From"bruno.desthuilliers@gmail.com" <bruno.desthuilliers@gmail.com>
Date2011-07-15 00:19 -0700
Message-ID<2df1dccd-a4ee-4edf-8986-f2afc3422ea3@q15g2000yqk.googlegroups.com>
In reply to#9510
On Jul 15, 8:36 am, Chris Angelico <ros...@gmail.com> wrote:
> This can alternatively be done with map():
>
> sortlist = map(lambda x,y: x+y, npalist, nxxlist)
>
>
> (It would have been a lot cleaner if Python exposed its operators as
> functions.

from operator import add



[toc] | [prev] | [next] | [standalone]


#9522

FromChris Angelico <rosuav@gmail.com>
Date2011-07-15 17:57 +1000
Message-ID<mailman.1056.1310716654.1164.python-list@python.org>
In reply to#9512
On Fri, Jul 15, 2011 at 5:19 PM, bruno.desthuilliers@gmail.com
<bruno.desthuilliers@gmail.com> wrote:
>> (It would have been a lot cleaner if Python exposed its operators as
>> functions.
>
> from operator import add

Ah yes, I forgot that module. Yep, that cleans up the code a bit.

ChrisA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web