I work in Python 3.8.0, I wanted to remove strings that began with a lowercase letter it does work only those strings are empty and those empty strings I can't remove. I have tried to strip it, and it works, but not for the empty strings. My code below
gezegdes_file = open(gezegdes_betekenis, 'r')
content = gezegdes_file.readlines()
gezegdes_file.close()
gezegdes_opgeschoond = open('gezegdes_opgeschoond.txt', 'w')
for rule in content:
rule = rule.replace(rule.lower(), ' ').strip()
# rule = "".join([s for s in rule.strip().splitlines(True) if s.strip("\r\n")])
rule = rule.replace('ij', 'y')
# rule = rule.replace('\n\n','\n').replace('\n\n','\n')
rule = rule.replace('.', '').replace('!', '').replace('?', '').upper()
print(rule)
gezegdes_opgeschoond.write(str(rule) + '\n')
gezegdes_opgeschoond.close()
I have tried to replace rule.lower by empty string and it works, but I can't remove the empty strings. Result of code below
AAN DE RAND VAN HET RAVYN BLOEIEN DE MOOISTE BLOEMEN
AAN DE VEREN KENT MEN DE VOGEL
AAN DE VRUCHTEN KENT MEN DE BOOM
AAP WAT HEB JE MOOIE JONGEN
ACHTER DE WOLKEN SCHYNT DE ZON
AL DOENDE LEERT MEN
AL IS DE LEUGEN NOG ZO SNEL, DE WAARHEID ACHTERHAALT HAAR WEL
ALLE GEKHEID OP EEN STOKJE
ALLE HENS AAN DEK
ALLE HOUT IS GEEN TIMMERHOUT
ALLE WEGEN LEIDEN NAAR ROME
ALS APEN HOGER KLIMMEN WILLEN, ZIET MEN GAUW HUN BLOTE BILLEN
And there is a white line between the two last sentences, and there was a string the began with a lowercase letter between the two last lines, and all strings that began with lowercase letter have I to remove. The file is quite long and there are several empty lines in the file like this because I have to removed the strings that began with a lowercase letter. What could be the solution to remove the white line between the two last sentences?