Cameron Laird wrote: > In article <[EMAIL PROTECTED]>, > Mathias Panzenboeck <[EMAIL PROTECTED]> wrote: > def fib(): > generation, parent_rabbits, baby_rabbits = 1, 1, 1 > while True: > yield generation, baby_rabbits > generation += 1 > parent_rabbits, baby_rabbits = \ > baby_rabbits, parent_rabbits + baby_rabbits > > for pair in fib(): > if pair[0] > 100: > break > print "Generation %d has %d (baby) rabbits." % pair > > as more appealing to non-Pythoneers. I'm still suspicious about > how they're going to react to itertools.islice(). Now, though, > I've begun to question my own sense of style ...
actually i don't like when a tutorial uses over complicated cute names if the context is obvious (fibonacci) then we don't need to add 'parent_rabbits' and such identifiers eg i find more readable and clear the following: def fib(): a, b = 0, 1 while True: yield a a, b = b, a + b for (n, fn) in enumerate(fib()): if n > 100: break print "F[%d] = %d" % (n, fn) ymmv -- http://mail.python.org/mailman/listinfo/python-list