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