forked from miczar1/djfz-24_25
D1 zrobione
This commit is contained in:
parent
db46cca450
commit
27252063f3
28
TaskD01/taskD1.py
Normal file
28
TaskD01/taskD1.py
Normal file
@ -0,0 +1,28 @@
|
||||
import re
|
||||
|
||||
final = []
|
||||
|
||||
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
|
||||
lines = file.readlines()
|
||||
pattern = r'(\w*[A-ZĄĆĘŁŃÓŚŹŻ]+[a-ząćęłńóśźż]+\w*)|(\w*[a-ząćęłńóśźż]+[A-ZĄĆĘŁŃÓŚŹŻ]+\w*)'
|
||||
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
x = re.findall(pattern, line)
|
||||
|
||||
if x:
|
||||
for words in x:
|
||||
if words[0] != '':
|
||||
to_replace = words[0]
|
||||
new_word = to_replace.swapcase()
|
||||
elif words[1] != '':
|
||||
to_replace = words[1]
|
||||
new_word = to_replace.swapcase()
|
||||
line = line.replace(to_replace, new_word, 1)
|
||||
print(line)
|
||||
final.append(line)
|
||||
|
||||
# with open('polish_wiki_excerpt.out', 'w', encoding='utf8') as file:
|
||||
# for line in final:
|
||||
# file.write(line + '\n')
|
Loading…
Reference in New Issue
Block a user