def wchoice(d):
	"""
	Given a dictionary of word: proportion, return a word randomly selected
	from the keys weighted by proportion.

	>>> wchoice({'a': 0, 'b': 1})
	'b'
	>>> choices = [wchoice({'a': 1, 'b': 2}) for x in range(1000)]

	Statistically speaking, choices should be .5 a:b
	>>> ratio = choices.count('a') / choices.count('b')
	>>> .4 < ratio < .6
	True
	"""
	total = sum(d.values())
	target = random.random() * total
	# elect the first item which pushes the count over target
	count = 0
	for word, proportion in d.items():
		count += proportion
		if count > target:
			return word
Given a dictionary of word: proportion, return a word randomly selected
	from the keys weighted by proportion.

	>>> wchoice({'a': 0, 'b': 1})
	'b'
	>>> choices = [wchoice({'a': 1, 'b': 2}) for x in range(1000)]

	Statistically speaking, choices should be .5 a:b
	>>> ratio = choices.count('a') / choices.count('b')
	>>> .4 < ratio < .6
	True