我可以读取整个字符串,但不计算单个字符。
这是我所拥有的:
#!/usr/bin/python2.7
ans = True
while ans:
print("""
1. Read in an text file.
Press enter to exit
""")
ans=raw_input("Make a selection")
if ans == "1":
print("Enter in a text file to open")
txt = raw_input("> ")
txt_open = open(txt, 'r')
d = dict()
for c in txt_open:
if c not in d:
d[c] = 1
else:
d[c] += 1
print d