How to convert Counter object to dict?

前端 未结 4 1791
独厮守ぢ
独厮守ぢ 2020-12-29 20:08

Data frame:

pair = collections.defaultdict(collections.Counter)

e.g.

pair = {\'doc1\':  {\'word1\':4, \'word2\':3}, 
               


        
4条回答
  •  误落风尘
    2020-12-29 20:32

    Maybe you are looking for:

    >>> from collections import defaultdict
    >>> pair = defaultdict(dict)
    >>> pair[3][2]='hello'
    >>>
    >>> pair
    defaultdict(, {3: {2: 'hello'}})
    >>>
    >>> pair[3]
    {2: 'hello'}
    >>> 
    

提交回复
热议问题