#!/usr/bin/python
#coding: utf-8
occur = {}
file = open('HW6 problem 6.txt')
lines = [list(line) for line in file.readlines()]
for line in lines:
for character in line:
if character not in occur:
occur[character] = 0
occur[character]+=1
for i in range(26):
key = chr(97+i)
Key = chr(65+i)
if key in occur:
print key, occur[key]
if Key in occur:
print Key, occur[Key]
随便找了一个文章测试,测试结果: