John Zenger wrote: > Also, with the functional programming tools of map, filter, and lambda, > this code can be reduced to just six lines: > > import random > > flips = map(lambda x: random.randrange(2), xrange(100)) > heads = len(filter(lambda x: x is 0, flips)) > tails = len(filter(lambda x: x is not 0, flips))
Or a filter/map/lambda free way: heads = sum(random.randrange(2) for x in xrange(100)) tails = 100 - heads -- http://mail.python.org/mailman/listinfo/python-list