Python- Count each letter in a list of words

后端 未结 7 1512
心在旅途
心在旅途 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:05

    An alternative approach using the iterator combinators in itertools:

    import collections
    import itertools
    
    cnt = collections.Counter(itertools.chain.from_iterable(itertools.imap(set, wordList)))
    

提交回复
热议问题