Py学习  »  Exosylver  »  全部回复
回复总数  1
6 年前
回复了 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()