Add tags

Add tags to the following comment

httplib.pyを解析させました。

spaceが多いのはインデントのせいでしょう。

辞書いいです。

[nori@Asama]~/Desktop/study/python/code% python count.py /usr/lib64/python2.4/httplib.py

{'\n': 1370, ' ': 14394, '"': 262, '(': 385, '*': 15, ',': 317, '.': 707, '0': 131, '2': 46, '4': 36, '6': 16, '8': 6, ':': 337, '<': 12, '>': 23, 'B': 22, 'D': 55, 'F': 52, 'H': 93, 'L': 78, 'N': 210, 'P': 112, 'R': 148, 'T': 313, 'V': 13, 'X': 25, 'Z': 4, '\\': 22, '`': 5, 'b': 215, 'd': 859, 'f': 1013, 'h': 761, 'j': 24, 'l': 1444, 'n': 1682, 'p': 606, 'r': 1429, 't': 1968, 'v': 182, 'x': 68, 'z': 26, '|': 19, '~': 1, '!': 12, '#': 224, '%': 18, "'": 220, ')': 390, '+': 21, '-': 127, '/': 39, '1': 110, '3': 18, '5': 20, '7': 6, '9': 19, ';': 8, '=': 440, '?': 8, 'A': 84, 'C': 109, 'E': 195, 'G': 16, 'I': 106, 'K': 17, 'M': 31, 'O': 104, 'Q': 22, 'S': 163, 'U': 64, 'W': 23, 'Y': 12, '[': 53, ']': 54, '_': 615, 'a': 1247, 'c': 809, 'e': 3748, 'g': 253, 'i': 1345, 'k': 254, 'm': 324, 'o': 1443, 'q': 60, 's': 2200, 'u': 579, 'w': 206, 'y': 169, '{': 5, '}': 5}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import sys

fn = sys.argv[1]

if not fn:
  sys.exit(1)

hist = dict()
f = file(fn)
buf = f.read(1000)
while buf:
  for ch in buf:
    count = hist.get(ch, 0)
    count +=1
    hist.update({ch:count})
  buf = f.read(1000)
print hist

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...