0
我正在嘗試僅對來自文本文件的字母進行計數。我想排除任何標點符號和空格。這是迄今爲止我所擁有的。我一直在尋找方法來做到這一點,但每當我嘗試排除某些字符時,我都會收到錯誤。任何幫助是極大的讚賞。Python從文本文件中創建字母數量
#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)
也許你想'計數器(在AText下c如果c.isalnum())' –