djfz-24_25/TaskA04/solution.py
2024-11-01 16:29:07 +01:00

30 lines
796 B
Python

import sys
# detect numbers. separate numbers by spaces
def solve(lines):
res = []
j = 0
for l in lines:
numbers = []
for i in range(len(l)):
c = l[i]
if j > 0 and not c.isdigit():
numbers.append(l[i-j:i])
j = j+1 if (c.isdigit() and c.isascii()) else 0
if numbers:
res.append(' '.join(numbers))
return '\n'.join(res)
if __name__ == "__main__":
lines = []
fp = sys.argv[1]
with open(fp, encoding="utf-8") as f:
lines = f.readlines()
sol = solve(lines)
with open("./polish_wiki_excerpt.out", 'w', encoding="utf-8") as f:
f.writelines(sol)
f.write('\n') # it expects for file to end with newline :)