Python style.

Kevin Russell krussell4 at videon.home.com
Wed May 10 11:48:34 EDT 2000


Fredrik Lundh wrote:

> Jacek Generowicz <jmg at ecs.soton.ac.uk> wrote:
> > How would you rewrite the following code, in good
> > python style ?
> >
> > list1 = [ 1,2,3,4,5,6 ]
> > list2 = [ 6,5,4,3,2,1 ]
> >
> > count = 0
> > for item in list1:
> >     print item - list2[count]
> >     count = count + 1
>
>
> the slightly more obscure way:
>
>     for item1, item2 in map(None, list1, list2):
>         ...
>

If you're going functional, you might as well go all the way:

     reduce(operator.add, map(operator.sub, l1, l2))

Still-speaking-Python-with-a-Scheme-accent-ly yours,
Kevin





More information about the Python-list mailing list