1
나는 텍스트 파일을 읽고 얼마나 많은 줄이 텍스트를 포함하는지에 대한 백분율로 텍스트의 TLA 양을 출력합니다.와 약어 Stop with python
import re
total_lines = 0
matched_lines = 0
for line in open("sentences.txt"):
total_lines += 1
matched_lines += bool(re.search(r"\b[A-Z]{3}\b", line))
matched_lines += bool(re.search(r"\b[A-Z]\\.[A-Z]\\.[A-Z]\b", line)) # DOES NOT WORK
print('{}% of sentences contain a TLA'.format(round(float(matched_lines)/total_lines * 100, 1)))
내가하려고하는 것은 TLA가 그들 사이에서 완전히 멈춘 상태입니다. 지금처럼 WWW를 계산하지만 W.W.W를 계산하기를 원합니다.
이 코드를 제공 한 이전 질문에 대한 대답을 수락하는 것을 잊지 마십시오. :) – TerryA