Is it what you search for?
Note: it will not filter the special characters
import re
from collections import Counter
filePath = #your file path
with open(filePath, 'r') as filePointer:
groupList = re.findall('..', filePointer.read())
outputString = ','.join(groupList)
print(outputString)
print(Counter(groupList))
For your example:
import re
from collections import Counter
test = 'hello world hello everybody'
groupList = re.findall('..', test)
outputString = ','.join(groupList)
print(outputString)
print(Counter(groupList)) #two chars
OUTPUT:
he,ll,o ,wo,rl,d ,he,ll,o ,ev,er,yb,od
Counter({'ll': 2, 'o ': 2, 'he': 2, 'od': 1, 'wo': 1, 'yb': 1, 'd ': 1, 'rl': 1, 'ev': 1, 'er': 1})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…