Python Lists - Finding Number of Times a String Occurs

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

    I like one-line solutions to problems like this:

    def tally_votes(l):
      return map(lambda x: (x, len(filter(lambda y: y==x, l))), set(l))
    

提交回复
热议问题