Python Lists - Finding Number of Times a String Occurs

后端 未结 8 467
独厮守ぢ
独厮守ぢ 2020-12-10 17:21

How would I find how many times each string appears in my list?

Say I have the word:

\"General Store\"

that is in my list like 20 t

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 17:47

    First use set() to get all unique elements of the list. Then loop over the set to count elements from the list

    unique = set(votes)
    for item in unique:
        print item
        print votes.count(item)
    

提交回复
热议问题