On Jun 22, 6:32 pm, cirfu <[EMAIL PROTECTED]> wrote:
> [a+b for a,b in zip(xrange(1,51), xrange(50,0,-1))]
>
> [51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
> 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
> 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51]
>
> i want to add all the elemtns a s well. can i do this all in a
> listcomprehension?
>
> i can do this ofc:
> reduce(lambda x,y:x+y,[a+b for a,b in zip(xrange(1,51),
> xrange(50,0,-1))])
>
> but reduce is a functional way of doing it, what is the more pythonic
> way of doing this?

Nothing that would be more concise than reduce.  Anything you did with
iteration would just mimic reduce in any case.

Jeff Ober
artfulcode.net
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to