diff --git a/TaskF00/run.py b/TaskF00/run.py new file mode 100644 index 0000000..60e4117 --- /dev/null +++ b/TaskF00/run.py @@ -0,0 +1,25 @@ +import re + +def substitute_digits(input_string): + def replace_digit(match): + digits = match.group() + replaced_digits = '' + for digit in digits: + if '0' <= digit <= '9': + replaced_digits += chr(ord('a') + int(digit)) + else: + replaced_digits += digit + return replaced_digits + + pattern = re.compile(r'\d{4}') + substituted_string = pattern.sub(replace_digit, input_string) + + return substituted_string + + +file_path = 'simple.in' +with open(file_path, 'r', encoding = 'utf-8') as file: + for line in file: + line = line.rstrip('\n') + result = substitute_digits(line) + print(result) diff --git a/TaskF01/run.py b/TaskF01/run.py new file mode 100644 index 0000000..d942ccf --- /dev/null +++ b/TaskF01/run.py @@ -0,0 +1,10 @@ +import re + +def process_file(file_path): + with open(file_path, 'r',encoding='utf-8') as file: + for line in file: + modified_line = re.sub(r'\b(?:[A-Z]+\w*[a-z]+\w*|[a-z]+\w*[A-Z]+\w*)\b', lambda match: match.group(0).swapcase(), line) + print(modified_line, end='') + +file_path = 'polish_wiki_excerpt.exp' +process_file(file_path) diff --git a/TaskF02/run.py b/TaskF02/run.py new file mode 100644 index 0000000..32300a3 --- /dev/null +++ b/TaskF02/run.py @@ -0,0 +1,23 @@ +import re + +def analyze_line(line): + result = re.findall(r'([a-ząćęłńóśźż])|([A-ZĄĆĘŁŃÓŚŹŻ])|(\d)|(\s)', line, flags=re.UNICODE) + + lower_case_letters = [match[0] for match in result if match[0]] + upper_case_letters = [match[1] for match in result if match[1]] + digits = [match[2] for match in result if match[2]] + special_characters = [match[3] for match in result if match[3]] + + result = f"{len(lower_case_letters)} {len(upper_case_letters)} {len(digits)} {len(special_characters)}" + return result + +def process_file(file_path): + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + line = line.rstrip('\n') + if line: + result = analyze_line(line) + print(result) + +file_path = 'simple.in' +process_file(file_path) diff --git a/TaskF03/run.py b/TaskF03/run.py new file mode 100644 index 0000000..035e039 --- /dev/null +++ b/TaskF03/run.py @@ -0,0 +1,13 @@ +import re + +def process_line(line): + words = re.findall(r'\b(?:[a-ząćęłńóśźż]+\w*|[A-ZĄĆĘŁŃÓŚŹŻ]+\w*)\b', line, flags=re.UNICODE) + lowercase_words = [word for word in words if word[0].islower()] + uppercase_words = [word for word in words if word[0].isupper()] + return f"{len(lowercase_words)} {len(uppercase_words)}" + +file_path = 'simple.in' +with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + result = process_line(line.strip()) + print(result) diff --git a/TaskF04/run.py b/TaskF04/run.py new file mode 100644 index 0000000..4d518ff --- /dev/null +++ b/TaskF04/run.py @@ -0,0 +1,22 @@ +import re + +def delete_second_digits(input_line): + regex = r'\b(\d+)\b' + numbers = re.findall(regex, input_line) + + if len(numbers) > 1: + second_number = numbers[1] + input_line = re.sub(re.escape(second_number), '', input_line, 1) + + return input_line + +file_path = 'simple.in' +output_lines = [] + +with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + modified_line = delete_second_digits(line) + output_lines.append(modified_line) + +for line in output_lines: + print(line, end='') diff --git a/TaskF04/simple.in b/TaskF04/simple.in index 5d7461c..99f4584 100644 --- a/TaskF04/simple.in +++ b/TaskF04/simple.in @@ -1,3 +1,6 @@ Mam 2 jabłka i 35 banananów. Mam 2 jabłka i 35 banananów oraz 20 gruszek. Widziałem 2 bociany. +2 35 209 +12 34 +532 234 234 324 \ No newline at end of file diff --git a/TaskF05/run.py b/TaskF05/run.py new file mode 100644 index 0000000..7e40f91 --- /dev/null +++ b/TaskF05/run.py @@ -0,0 +1,15 @@ +import re + +def process_line(line): + words = re.findall(r'\w+', line) + if len(words) >= 3: + third_word = words[2] + replacement = 'x' * len(third_word) + line = re.sub(r'\b' + re.escape(third_word) + r'\b', replacement, line) + + return line + +with open('simple.in', 'r', encoding='utf-8') as file: + for line in file: + processed_line = process_line(line) + print(processed_line, end='')