Group/Count list of dictionaries based on value

前端 未结 4 1657
小蘑菇
小蘑菇 2021-02-13 13:38

I\'ve got a list of Tokens which looks something like:

[{
    Value: \"Blah\",
    StartOffset: 0,
    EndOffset: 4
}, ... ]

What I want to do

4条回答
  •  忘掉有多难
    2021-02-13 14:12

    import collections
    
    # example token list
    tokens = [{'Value':'Blah', 'Start':0}, {'Value':'BlahBlah'}]
    
    count=collections.Counter([d['Value'] for d in tokens])
    print count
    

    shows

    Counter({'BlahBlah': 1, 'Blah': 1})
    

提交回复
热议问题