Python- Count each letter in a list of words

后端 未结 7 1517
心在旅途
心在旅途 2021-01-16 05:46

So I have a list of words `wordList = list().\' Right now, I am counting each letter in each of the words throughout the whole list using this code

cnt = C         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-16 06:24

    Add a set call:

    cnt = Counter()
    for word in wordList:
          for letter in set(word):
              cnt[letter]+=1
    

提交回复
热议问题