我所需要的前10话和他们的数量,已经包含在字典中,按以下格式:顶部计数...返回输出的元组格式返回给字典格式
字计数(例如招呼10)
我有以下代码:
for word in word:
if word not in counts:
counts[word] = 1
else:
counts[word] += 1
for word in counts:
top = sorted(counts.items())
top_10 = top[:9]
print top
输出是与内部的元组的列表:[( '红',5),( '蓝色',2),( '绿色',1), ...]
但是,我需要它在f的ORMAT:
红5
蓝2
绿色1
如何才能做到这一点???
你可以把你的单词列表在这里 –