TaskF04
This commit is contained in:
parent
3f957f6706
commit
d7877f4f5f
@ -1,29 +1,38 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
def analyze_line(line):
|
||||
lowercase_count = len(re.findall(r'\b[a-ząćęłńóśźż]\w*\b', line))
|
||||
uppercase_count = len(re.findall(r'\b[A-ZĄĆĘŁŃÓŚŹŻ]\w*\b', line))
|
||||
|
||||
result_line = f"{lowercase_count} {uppercase_count}\n"
|
||||
return result_line
|
||||
|
||||
def replace_second_number(line):
|
||||
pattern = re.compile(r'(\D*\d+\D*).*?(\d+)(.*)')
|
||||
group1, group2, group3 = '', '', ''
|
||||
matches = pattern.search(line)
|
||||
if matches:
|
||||
group1 = matches.group(1)
|
||||
group2 = matches.group(2)
|
||||
group3 = matches.group(3)
|
||||
print('group1:', group1)
|
||||
print('group2:', group2)
|
||||
print('group3:', group3)
|
||||
if group2 != '':
|
||||
modified_line = group1 + group3
|
||||
return modified_line
|
||||
else:
|
||||
return line
|
||||
|
||||
def write_answer(row, ouput_file):
|
||||
with open(ouput_file, "a", encoding="utf-8") as file:
|
||||
file.write(row)
|
||||
file.write(row+'\n')
|
||||
|
||||
|
||||
def main_function(input_file, output_file):
|
||||
with open(output_file, "w", encoding="utf-8") as output_file1:
|
||||
with open(input_file, "r", encoding="utf-8") as file:
|
||||
for row in file:
|
||||
write_answer(analyze_line(row), output_file)
|
||||
write_answer(replace_second_number(row), output_file)
|
||||
|
||||
output_file ='simple.out'
|
||||
input_file = 'simple.in'
|
||||
# input_file = sys.argv[1]
|
||||
# output_file = sys.argv[2]
|
||||
# output_file ='simple.out'
|
||||
# input_file = 'simple.in'
|
||||
input_file = sys.argv[1]
|
||||
output_file = sys.argv[2]
|
||||
main_function(input_file, output_file)
|
||||
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
Mam 2 jabłka i 35 banananów.
|
||||
Mam 2 jabłka i 35 banananów oraz 20 gruszek.
|
||||
Widziałem 2 bociany.
|
||||
Widziałem 2 bociany.
|
3
TaskF04/simple.out
Normal file
3
TaskF04/simple.out
Normal file
@ -0,0 +1,3 @@
|
||||
Mam 2 jabłka i banananów.
|
||||
Mam 22 jabłka i banananów oraz 20 gruszek.
|
||||
Widziałem 2 bociany.
|
Loading…
Reference in New Issue
Block a user