【发布时间】:2018-04-01 04:16:27
【问题描述】:
无法在空闲 python 2.7.14 上运行函数调用表达式。下面的代码可能有什么问题?
fruit = ['apple', 'orange', 'grape', 'apple',
'orange', 'grape', 'kiwi'] # init the array
#reports the frequency of every item in a list
def analyze_list(l):
counts = {}
for item in l:
if item in counts:
counts[item] = counts[item] + 1
else:
counts[item] = 1
return counts
#let analyze a list
counts = analyze_list(fruit)
print counts
【问题讨论】:
-
您知道 Python 中的缩进很重要,对吧?您的 if-else 缩进错误。