Can you make Counter not write-out “Counter”?

后端 未结 4 1747
渐次进展
渐次进展 2021-01-15 13:22

So when I print the Counter (from collections import Counter) to a file I always get this the literal Counter ({\'Foo\': 12})

Is there anyw

4条回答
  •  渐次进展
    2021-01-15 13:42

    Well this isn't very elegant, but you can simply cast it as a string and cut off the first 8 and last 1 letters:

    x = Counter({'Foo': 12})
    print str(x)[8:-1]
    

提交回复
热议问题