On Thu, Oct 23, 2008 at 10:20 AM, bob gailer <[EMAIL PROTECTED]> wrote:

> import operator
> ops = (operator.add, operator.sub)
> x = 0
> m = 0
> for in in range...
>   x = ops[m](x, 4.0/i)
>   m =  1-m

itertools.cycle(ops) is handy here. Hmm, there is a cute one-line
solution (excluding import and input) that uses itertools.cycle() and
zip()...not sure if this is a homework problem so I won't post it
yet...

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to