方案一 统计字符串中的字母频数
import collections
import re
d = collections.defaultdict(int)
S = "testTypecopyri4g3HACBCtcFor the ginpraise.ll be dog ssditsl-+-___*&^%icense()ation."
#convert to lower case
s = S.lower()
#match non-letter chars
rule = re.compile(r"[^a-z]")
#delete non-letter chars
s_result = rule.sub("", s)
#calculate the couter
for c in s_result:
d[c] += 1
print d
#rank according to the letter
print sorted(d.iteritems(), key = lambda d:d[0])
#rank according to the counter
print sorted(d.iteritems(), key = lambda d:d[1])
方案二 统计字符串中的字母频率
import collections
import re
sum = 0
d = collections.defaultdict(float)
S = "testTypecopyri4g3HACBCtcFor the ginpraise.ll