私信  •  关注

Exosylver

Exosylver 最近创建的主题
Exosylver 最近回复了
5 年前
回复了 Exosylver 创建的主题 » 如何用python计算列表中的单词列表

words =[]


def count_the_fruits():
    for fruit in fruits:
        if words.count(fruit) >=1:
            continue
        words.append((fruit, fruits.count(fruit)))
    print(words)


fruits = ["apple", "banana","grape", "kiwi", "banana", "apple", "apple", "watermelon", "kiwi", "banana", "apple"]
count_the_fruits()