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


Groups > comp.lang.python > #9510

Re: Please critique my script

References <77AE044B1BF3944FAE2435F395F11B4B01859CD7@clt-exmb02.bbtnet.com>
Date 2011-07-15 16:36 +1000
Subject Re: Please critique my script
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1047.1310711795.1164.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

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

csiph-web