Basic coin flipper program - logical error help

bonono at gmail.com bonono at gmail.com
Tue Feb 21 22:27:38 EST 2006


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




More information about the Python-list mailing list