def frequencies(data):
data.sort()
count = 0
previous = data[0]
print("data\tfrequency") # '\t' is the TAB character
for d in data:
if d == previous:
# same as the previous, so just increment the count
count += 1
else:
# we've found a new item so print out the old and reset the count
print(str(previous) + "\t" + str(count))
count = 1
previous = d
所以我有这个频率代码,但是它每次都在我的列表中留下最后一个数字。Python中的频率
它可能与我之前开始的位置或可能在最后重置d前的位置有关。
谢谢,但我必须保持它的代码是当前设置方式,只要解决了一行代码 – carroll