In article <[EMAIL PROTECTED]>, Mathias Panzenboeck <[EMAIL PROTECTED]> wrote: >Steve Howell schrieb: >> --- "[EMAIL PROTECTED]" >> <[EMAIL PROTECTED]> wrote: >> >>> Is there a resource somewhere on the net that can be >>> used to quickly >>> and effectively show Python's strengths to >>> non-Python programmers? >>> Small examples that will make them go "Wow, that >>> _is_ neat"? >>> >> >> 15 small programs here: >> >> http://wiki.python.org/moin/SimplePrograms >> > >IMHO a few python goodies are missing there. >e.g. generator functions: > ># generic fibonacci without upper bound: >def fib(): > parent_rabbits, baby_rabbits = 1, 1 > while True: > yield baby_rabbits > parent_rabbits, baby_rabbits = baby_rabbits, parent_rabbits + >baby_rabbits > > ># only calculate and print the first 100 fibonacci numbers: >from itertools import islice > >for baby_rabbits in islice(fib(),100): > print 'This generation has %d rabbits' % baby_rabbits
Good point. This example intrigues me. When I saw the first couple of lines, I expected 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 ... -- http://mail.python.org/mailman/listinfo/python-list