Python Lists - Finding Number of Times a String Occurs

后端 未结 8 466
独厮守ぢ
独厮守ぢ 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:43

    just a simple example:

       >>> lis=["General Store","General Store","General Store","Mall","Mall","Mall","Mall","Mall","Mall","Ice Cream Van","Ice Cream Van"]
       >>> for x in set(lis):
            print "{0}\n{1}".format(x,lis.count(x))
    
    
        Mall
        6
        Ice Cream Van
        2
        General Store
        3
    

提交回复
热议问题