# I'm trying to make a Zipf's Law observation using a dictionary that stores every word, and a counter for it. I will later sort this from ascending to descending to prove Zipf's Law in a particular text. I'm taking most of this code from Automate the Boring Stuff with Python, where the same action is performed, but using letters instead.
message = 'the of'
words = message.split()
wordsRanking = {}
for i in words:
wordsRanking.setdefault(words[i], 0)
wordsRanking[i] += 1
print(wordsRanking)
这段代码给了我以下错误:
TypeError: list indices must be integers or slices, not str
我该如何解决这个问题?我将不胜感激。