from __future__ import division # 4. Dice may not have any memory, but apparently the roulette wheel at the Learn Challenge Casino does. You've received a tip-off that the wheel has some exploitable bias where the probability of landing on a given number changes depending on the number previously landed on. Analyze a list containing a history of roulette spins. #Return a dictionary where the keys are numbers on the roulette wheel, and the values are dictionaries mapping numbers on the wheel to probabilities, such that `d[n1][n2]` is an estimate of the probability that the next spin will land on n2, given that the previous spin landed on n1. def conditional_roulette_probs(history): """ Example: conditional_roulette_probs([1, 3, 1, 5, 1]) > {1: {3: 0.5, 5: 0.5}, 3: {1: 1.0}, 5: {1: 1.0} } """ roulette_dict = dict() for i in range(len(history)-1): num1 = history[i] num2 = history[i+1] if num1 not in roulette_dict: roulette_dict[num1] = dict() roulette_dict[num1][num2] = 1 else: if num2 in roulette_dict[num1]: roulette_dict[num1][num2]+=1 else: roulette_dict[num1][num2]=1 # now convert them to prob for each in roulette_dict: itemDict = roulette_dict[each] sum = 0 for i in itemDict: sum+=itemDict[i] for i in itemDict: itemDict[i]/=sum return roulette_dict print(conditional_roulette_probs([1, 3, 1, 5, 1]))