I have a small function that counts occurrence of characters in a string. It works for me in some places, but not in others. Specifically in Jupyter is not going well and I do not know the reason. Thanks.
def char_frequency(str1):
dict = {}
for n in str1:
keys = dict.keys()
if n in keys:
dict[n] += 1
else:
dict[n] = 1
return dict