我只想从一个文本文件中数一数字母。我想排除任何标点和空格。这是我目前掌握的情况。我一直在寻找这样做的方法,但每当我试图排除某些字符时,总是会出现错误。非常感谢您的帮助。你知道吗
#Read Text Files To Memory
with open("encryptedA.txt") as A:
AText = A.read()
with open("encryptedB.txt") as B:
BText = B.read()
#Create Dictionary Object
from collections import Counter
CountA = Counter(AText)
print(CountA)
CountB = Counter(BText)
print(CountB)
您的思路是正确的,但是您希望根据字母(使用
isalpha()
)或字母数字(使用isalnum()
)的字符筛选文本文件:对于我的示例文件,这个打印:
相关问题 更多 >
编程相关推荐