我正在尝试计算字母出现次数并打印出来。这是我到目前为止所拥有的:
def histogram(L):
d = {}
for x in L:
for letter in x:
if letter in d:
d[letter] += 1
else:
d[letter] = 1
for i in range(len(d)):
print('{} | {}'.format(d, d[i])) # GETTING ERRORS ON THIS LINE
return d
histogram(open('cipher.txt'))
出于某种原因,我在那条线上遇到了错误。我将如何正确打印它?
编辑:解决我的Martijn!道具!但有谁知道如何按字母顺序对字典进行排序?