In [35]:
from collections import Counter
profile = Counter({"Arts":0, "Business":0, "Computers":0,"Games":2, "Health":0, "Home":0,
"Kids and Teens":0, "News":1, "Recreation":3, "Reference":0, "Regional":0,
"Science":0, "Shopping":0, "Society":0, "Sports":0,"World":0})
In [52]:
def calculate_relative_profile(profile):
rel_profile = profile.values()
new_profile = dict()
rel_sum = sum(rel_profile)
for item in profile.items():
new_profile[item[0]] = float(float(item[1])/float(rel_sum))
return new_profile
In [53]:
new_profile = calculate_relative_profile(profile)
print new_profile
In [ ]: