frequence table
作者:互联网
fruit = ['orange', 'orange', 'orange', 'banana',
'apple', 'banana', 'orange', 'banana',
'apple', 'banana']
fruit_frequency = {}
for f in fruit:
if f not in fruit_frequency:
fruit_frequency[f] = 1
else:
fruit_frequency[f] += 1
print(fruit_frequency)
{‘orange’: 1}
{‘orange’: 2}
{‘orange’: 3}
{‘orange’: 3, ‘banana’: 1}
{‘orange’: 3, ‘banana’: 1, ‘apple’: 1}
{‘orange’: 3, ‘banana’: 2, ‘apple’: 1}
{‘orange’: 4, ‘banana’: 2, ‘apple’: 1}
{‘orange’: 4, ‘banana’: 3, ‘apple’: 1}
{‘orange’: 4, ‘banana’: 3, ‘apple’: 2}
{‘orange’: 4, ‘banana’: 4, ‘apple’: 2}
标签:apple,frequence,fruit,frequency,orange,table,banana 来源: https://blog.csdn.net/qq_44271529/article/details/90271441