1
0
forked from miczar1/djfz-24_25

D2 zrobione

This commit is contained in:
LuminoX 2025-01-28 21:35:38 +01:00
parent 27252063f3
commit 7dacb80485

39
TaskD02/taskD2.py Normal file
View File

@ -0,0 +1,39 @@
import re
final = []
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
lines = file.readlines()
pattern = r'([a-ząćęłńóśźż]+)|([A-ZĄĆĘŁŃÓŚŹŻ]+)|(\d+)'
for line in lines:
#line = line.strip()
line = line.replace('\n', '')
x = re.findall(pattern, line)
a = 0
b = 0
c = 0
d = 0
if x:
for words in x:
if words[0] != '':
matching = words[0]
a += len(matching)
elif words[1] != '':
matching = words[1]
b += len(matching)
elif words[2] != '':
matching = words[2]
c += len(matching)
d = len(line) - a - b - c
print(a, b, c, d)
final.append([a, b, c, d])
with open('polish_wiki_excerpt.out', 'w', encoding='utf8') as file:
for line in final:
for number in line:
file.write(str(number)+ ' ')
file.write('\n')