bash:

grep -o . myfile | sort |uniq -c

 

python:  使用collections模块

import pprint
import collections


f = 'xxx'
with open(f) as info:
    count = collections.Counter(info.read().upper())
    value = pprint.pformat(count)
    
    print(value)
    

 或

import codecs

f = 'xxx'
with codecs.open(f, 'r', 'utf-8') as tf:
    for l in tf:
        for ch in l:
            c[ch] = c.setdefault(ch, 0) + 1

print json.dumps(c, ensure_ascii=False, encoding='utf-8', indent=4)

 

相关文章:

  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2022-01-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
  • 2021-12-11
相关资源
相似解决方案