【发布时间】:2015-10-24 01:58:08
【问题描述】:
第一个结构:
dic = {'l':2, 'o':3, 'p':6}
for key in dic:
total = [dic[key]]
print max(total)
输出为 6
第二个结构:
dic = {}
print 'Enter line of text'
line = input('')
words = line.split()
print 'Words', words
print 'Counting'
for word in words:
dic[word] = dic.get(word,0) + 1
print 'Dictionary of your text', dic
for num in dic:
total = [dic[num]]
print max(total)
输出为 1,大部分为 1
【问题讨论】:
-
total = [dic[num]]应该做什么?您只存储一个值,即最后一个dic[num]
标签: python python-2.7 for-loop dictionary max