jfz-2023-s473564/TaskA04/run.py

46 lines
1.1 KiB
Python
Raw Normal View History

2023-10-26 20:28:12 +02:00
def is_number(char):
numbers = ['0','1','2','3','4','5','6','7','8','9']
for i in numbers:
if char == i:
return True
path = "TaskA04\polish_wiki_excerpt.exp"
file = open(path,"r",encoding="utf8")
count = 0
length = 0
digits = []
digit = ""
all_lines = file.readlines()
for l in all_lines:
line_length = len(l.strip())
used = False
space = False
count = 0
i = 0
for char in l:
i += 1
if i == 1:
space = True
if char == " " or line_length == (i-1):
space = True
if count != 0:
if length == 0:
length = count
digits.append(digit)
elif count > length:
length = count
digits.clear()
digits.append(digit)
elif count == length:
digits.append(digit)
digit = ""
count = 0
elif is_number(char) == True and space == True:
count += 1
digit += char
else:
count = 0
digit = ""
print(digits)
file.close()