不使用计数器创建字典

Creating a dictionary without using counter

INFO 是一个 list,我正在使用 Counter 对其进行排序,并希望输出采用字典的形式。但是,我得到了不必要的字符:

wanted_dict = collections.Counter(INFO)
>>> Counter({'BLA': 102, 'BLABLA': 96, 'BLABLABLA': 96...})

不必要的字符是:

Counter
(
)

有没有办法输出以下内容?

>>> {'BLA': 102, 'BLABLA': 96, 'BLABLABLA': 96...}

只需将其包装在 dict 调用中即可。

>>> dict(Counter({'BLA': 102, 'BLABLA': 96, 'BLABLABLA': 96}))
{'BLABLABLA': 96, 'BLABLA': 96, 'BLA': 102}

您可以使用此方法将最特殊的 collections 词典对象转换为普通词典。