best way to do some simple tasks

Mike Meyer mwm at mired.org
Wed Jan 29 23:34:58 EST 2003


Jp Calderone <exarkun at intarweb.us> writes:
> On Wed, Jan 29, 2003 at 03:31:59PM -0800, Erik Lechak wrote:
> > 3) What is the best way to do this?
> > 
> >    a=[1,2,3]
> >    b=[1,1,1]
> >    
> >    how do I get c=a+b (c=[2,3,4])?
> > 
>      import operator
>      c = map(operator.add, a, b)

You can save the import with a bit of extra ugliness:

        c = map(int.__add__, a, b)


        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.




More information about the Python-list mailing list