在
Counter类中
collections模块是专为解决这类问题的目的:
from collections import Counterwords = "apple banana apple strawberry banana lemon"Counter(words.split())# Counter({'apple': 2, 'banana': 2, 'strawberry': 1, 'lemon': 1})
在
Counter类中
collections模块是专为解决这类问题的目的:
from collections import Counterwords = "apple banana apple strawberry banana lemon"Counter(words.split())# Counter({'apple': 2, 'banana': 2, 'strawberry': 1, 'lemon': 1})