# Here's a less crude rewrite
# It reflects conditional probability better
def boy_girl_problem():
from random import choice
families = {}
for i in range(1000):
families[i] = []
families[i].append(choice(['BOY', 'GIRL']))
families[i].append(choice(['BOY', 'GIRL']))
had_both_sex = filter(lambda f: set(f) == set(['BOY', 'GIRL']), families.values())
had_one_girl = filter(lambda f: 'GIRL' in f, families.values())
return len(had_both_sex) / float(len(had_one_girl))
# The fact as ALREADY happened.
# BG/GB being DIFFERENT is NOT THE TWIST.
# Whether they are or not it will amount to 50% total.
# TWIST: BB is not possible.
# average(boy_girl_problem) == 2/3