djfz-2020-s444507/TaskD01/run.py

39 lines
721 B
Python
Raw Normal View History

2020-12-05 20:41:36 +01:00
import re
import sys
def repl(char):
x = char.group(0)
output_str = ""
for c in x:
c = c.swapcase()
output_str += c
return output_str
2020-12-06 15:18:14 +01:00
pattern = re.compile(r"\b[a-ząćęłńóśźż]+[A-ZĄĆĘŁŃÓŚŹŻ]+\b|\b[A-ZĄĆĘŁŃÓŚŹŻ]+[a-ząćęłńóśźż]+\b")
# f = open("polish_wiki_excerpt.in", "r")
def change_line(word_list, curr_line):
for word in word_list:
curr_line = curr_line.replace(word, word.swapcase())
2020-12-06 15:30:31 +01:00
return curr_line.rstrip('\n')
2020-12-06 15:18:14 +01:00
2020-12-06 15:30:31 +01:00
for line in open("./polish_wiki_excerpt.in", encoding="utf8"):
# for line in sys.stdin:
2020-12-06 15:18:14 +01:00
found_words = re.findall(pattern, line)
out = change_line(found_words, line)
2020-12-06 15:30:31 +01:00
if out:
print(out)
2020-12-06 15:18:14 +01:00