Group/Count list of dictionaries based on value

前端 未结 4 1658
小蘑菇
小蘑菇 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:00

    token = [{
        'Value': "Blah",
        'StartOffset': 0,
        'EndOffset': 4
    }, ... ]
    
    value_counter = {}
    
    for t in token:
        v = t['Value']
        if v not in value_counter:
            value_counter[v] = 0
        value_counter[v] += 1
    
    print value_counter
    

提交回复
热议问题