Compare commits
38 Commits
Author | SHA1 | Date | |
---|---|---|---|
97eb3536f6 | |||
3da2b5d83d | |||
2045b4eb99 | |||
dab5c629c6 | |||
8c0af38006 | |||
077f7fa966 | |||
639d5f9356 | |||
4c38c40be3 | |||
81740936e6 | |||
7dacb80485 | |||
27252063f3 | |||
db46cca450 | |||
afed3aee82 | |||
d5bf1e39ad | |||
63dd0e9716 | |||
0b736cfdd8 | |||
0c8d519bde | |||
4afd894364 | |||
cea1d6bd49 | |||
bb99e42844 | |||
c726906fcd | |||
d7a9ac3994 | |||
34e284c49e | |||
b718541d69 | |||
a7892ad185 | |||
834f781e2c | |||
53e7341220 | |||
956123d97e | |||
348556373e | |||
ed65fd5535 | |||
bcc3d7344f | |||
37f63d6317 | |||
f6dd2eef8c | |||
0beb5c2db5 | |||
c8de88b936 | |||
bf20d2f3a0 | |||
d9c12d5d2f | |||
35dfc38168 |
11
TaskA01/task1.py
Normal file
11
TaskA01/task1.py
Normal file
@ -0,0 +1,11 @@
|
||||
with open("shakespeare.in", encoding="utf8") as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
line = line.split()
|
||||
for word in line:
|
||||
if word[:6] == "Hamlet":
|
||||
result = " ".join(line)
|
||||
print(result)
|
||||
break
|
||||
|
5
TaskA02/task2.py
Normal file
5
TaskA02/task2.py
Normal file
@ -0,0 +1,5 @@
|
||||
with open("polish_wiki_excerpt.in", encoding="utf8") as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
if "Pies " in line or " pies " in line or "pies\n" in line:
|
||||
print(line.strip("\n"))
|
File diff suppressed because one or more lines are too long
23
TaskA03/task3.py
Normal file
23
TaskA03/task3.py
Normal file
@ -0,0 +1,23 @@
|
||||
with open("polish_wiki_excerpt.in", encoding="utf-8") as f:
|
||||
lines = f.readlines()
|
||||
result = []
|
||||
for line in lines:
|
||||
line = line.replace('\xa0', '[NBA]').strip() # eliminujemy problem z 'non breaking space'
|
||||
line = line.split()
|
||||
|
||||
flag1 = False
|
||||
|
||||
for word in line:
|
||||
if flag1:
|
||||
if word[:2] == 'r.':
|
||||
goodLine = ' '.join(line)
|
||||
result.append(goodLine)
|
||||
print(goodLine)
|
||||
break
|
||||
else:
|
||||
flag1 = False
|
||||
if word[-4:-2] == '19':
|
||||
if word[-2] in '0123456789' and word[-1] in '0123456789':
|
||||
flag1 = True
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
27
TaskA04/task4.py
Normal file
27
TaskA04/task4.py
Normal file
@ -0,0 +1,27 @@
|
||||
with open('polish_wiki_excerpt.in', encoding='utf8') as f:
|
||||
lines = f.readlines()
|
||||
results = []
|
||||
i = 0
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
|
||||
subdigits = []
|
||||
pom = ''
|
||||
|
||||
for char in line:
|
||||
if char in '0123456789':
|
||||
pom += char
|
||||
elif pom != '':
|
||||
subdigits.append(pom)
|
||||
pom = ''
|
||||
else:
|
||||
pass
|
||||
|
||||
if pom.isdigit():
|
||||
subdigits.append(pom)
|
||||
|
||||
if len(subdigits) > 0:
|
||||
finalLine = ' '.join(subdigits)
|
||||
print(finalLine)
|
||||
|
||||
|
10
TaskB01/task1.py
Normal file
10
TaskB01/task1.py
Normal file
@ -0,0 +1,10 @@
|
||||
import regex as re
|
||||
|
||||
with open('shakespeare.in', encoding='utf8') as file:
|
||||
lines = file.readlines()
|
||||
pattern = re.compile(r'Hamlet')
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
x = re.search(pattern, line)
|
||||
if x:
|
||||
print(line)
|
10
TaskB02/task2.py
Normal file
10
TaskB02/task2.py
Normal file
@ -0,0 +1,10 @@
|
||||
import regex as re
|
||||
|
||||
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
|
||||
lines = file.readlines()
|
||||
pattern = r'(P|( p))ies(( \w+)|(\.$))'
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
x = re.search(pattern, line)
|
||||
if x:
|
||||
print(line)
|
File diff suppressed because one or more lines are too long
10
TaskB03/task3.py
Normal file
10
TaskB03/task3.py
Normal file
@ -0,0 +1,10 @@
|
||||
import re
|
||||
|
||||
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
|
||||
lines = file.readlines()
|
||||
pattern = r'19\d\d r\.'
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
x = re.search(pattern, line)
|
||||
if x:
|
||||
print(line)
|
File diff suppressed because one or more lines are too long
10
TaskB04/task4.py
Normal file
10
TaskB04/task4.py
Normal file
@ -0,0 +1,10 @@
|
||||
import re
|
||||
|
||||
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
|
||||
lines = file.readlines()
|
||||
pattern = r'\d+'
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
x = re.findall(pattern, line)
|
||||
if x:
|
||||
print(' '.join(x))
|
25
TaskC02/task2.py
Normal file
25
TaskC02/task2.py
Normal file
@ -0,0 +1,25 @@
|
||||
import re
|
||||
|
||||
pattern = re.compile(r'^\d{2}-\d{3}$')
|
||||
|
||||
def check(given_text):
|
||||
result = re.search(pattern, given_text)
|
||||
if result:
|
||||
return given_text[:2]
|
||||
else:
|
||||
return '<NONE>'
|
||||
|
||||
### test
|
||||
|
||||
# with open('test.in', 'r', encoding='utf-8') as f:
|
||||
# lines = f.readlines()
|
||||
# for line in lines:
|
||||
# line = line.strip()
|
||||
# print(check(line))
|
||||
|
||||
while True:
|
||||
text = input('Please provide your text: ')
|
||||
if text == 'END':
|
||||
break
|
||||
print(check(text))
|
||||
print('To end type END')
|
27
TaskC10/task10.py
Normal file
27
TaskC10/task10.py
Normal file
@ -0,0 +1,27 @@
|
||||
import re
|
||||
|
||||
pattern = re.compile(r'^[1248]0*$')
|
||||
|
||||
def check(given_text):
|
||||
result = re.search(pattern, given_text)
|
||||
if result:
|
||||
return 'yes'
|
||||
else:
|
||||
return 'no'
|
||||
|
||||
|
||||
|
||||
### test
|
||||
|
||||
# with open('test.in', 'r', encoding='utf-8') as f:
|
||||
# lines = f.readlines()
|
||||
# for line in lines:
|
||||
# line = line.strip()
|
||||
# print(check(line))
|
||||
|
||||
while True:
|
||||
text = input('Please provide your text: ')
|
||||
if text == 'END':
|
||||
break
|
||||
print(check(text))
|
||||
print('To end type END')
|
25
TaskC42/task42.py
Normal file
25
TaskC42/task42.py
Normal file
@ -0,0 +1,25 @@
|
||||
import re
|
||||
|
||||
pattern = re.compile(r'^N((I[E]{6,})|([O]{6,}))[!]{3,}$')
|
||||
|
||||
def check(given_text):
|
||||
result = re.search(pattern, given_text)
|
||||
if result:
|
||||
return 'yes'
|
||||
else:
|
||||
return 'no'
|
||||
|
||||
### test
|
||||
|
||||
# with open('test.in', 'r', encoding='utf-8') as f:
|
||||
# lines = f.readlines()
|
||||
# for line in lines:
|
||||
# line = line.strip()
|
||||
# print(check(line))
|
||||
|
||||
while True:
|
||||
text = input('Please provide your text: ')
|
||||
if text == 'END':
|
||||
break
|
||||
print(check(text))
|
||||
print('To end type END')
|
25
TaskC47/task47.py
Normal file
25
TaskC47/task47.py
Normal file
@ -0,0 +1,25 @@
|
||||
import re
|
||||
|
||||
pattern = re.compile(r'#[a-zA-Z]\w*')
|
||||
|
||||
def check(given_text):
|
||||
result = re.findall(pattern, given_text)
|
||||
if result:
|
||||
return ';'.join(result)
|
||||
else:
|
||||
return '<NONE>'
|
||||
|
||||
### test
|
||||
|
||||
# with open('test.in', 'r', encoding='utf-8') as f:
|
||||
# lines = f.readlines()
|
||||
# for line in lines:
|
||||
# line = line.strip()
|
||||
# print(check(line))
|
||||
|
||||
while True:
|
||||
text = input('Please provide your text: ')
|
||||
if text == 'END':
|
||||
break
|
||||
print(check(text))
|
||||
print('To end type END')
|
File diff suppressed because one or more lines are too long
37
TaskD00/taskD0.py
Normal file
37
TaskD00/taskD0.py
Normal file
@ -0,0 +1,37 @@
|
||||
import re
|
||||
|
||||
dictionary = {
|
||||
'0': 'a',
|
||||
'1': 'b',
|
||||
'2': 'c',
|
||||
'3': 'd',
|
||||
'4': 'e',
|
||||
'5': 'f',
|
||||
'6': 'g',
|
||||
'7': 'h',
|
||||
'8': 'i',
|
||||
'9': 'j',
|
||||
}
|
||||
final = []
|
||||
|
||||
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
|
||||
lines = file.readlines()
|
||||
pattern = r'\d{4}'
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
x = re.findall(pattern, line)
|
||||
|
||||
if x:
|
||||
for words in x:
|
||||
decoded_word = ''
|
||||
for char in words:
|
||||
decoded_word += dictionary[char]
|
||||
line = line.replace(words, decoded_word, 1)
|
||||
print(line)
|
||||
final.append(line)
|
||||
|
||||
with open('polish_wiki_excerpt.out', 'w', encoding='utf8') as file:
|
||||
for line in final:
|
||||
file.write(line + '\n')
|
||||
|
File diff suppressed because one or more lines are too long
46
TaskD01/taskD1.py
Normal file
46
TaskD01/taskD1.py
Normal file
@ -0,0 +1,46 @@
|
||||
import re
|
||||
|
||||
final = []
|
||||
polish_big = 'AĄBCĆDEĘFGQHIJKLŁMNŃOÓPRSŚTUWXVYZŹŻ'
|
||||
polish_small = 'aąbcćdeęfgqhijklłmnńoóprsśtuwxvyzźż'
|
||||
|
||||
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
|
||||
lines = file.readlines()
|
||||
pattern = r'(\w*[A-ZĄĆĘŁŃÓŚŹŻ]+[a-ząćęłńóśźż]+\w*)|(\w*[a-ząćęłńóśźż]+[A-ZĄĆĘŁŃÓŚŹŻ]+\w*)'
|
||||
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
x = re.findall(pattern, line)
|
||||
|
||||
if x:
|
||||
for words in x:
|
||||
if words[0] != '':
|
||||
to_replace = words[0]
|
||||
new_word = ''
|
||||
for char in to_replace:
|
||||
if char in polish_big:
|
||||
new_word += char.lower()
|
||||
elif char in polish_small:
|
||||
new_word += char.upper()
|
||||
else:
|
||||
new_word += char
|
||||
elif words[1] != '':
|
||||
to_replace = words[1]
|
||||
new_word = ''
|
||||
for char in to_replace:
|
||||
if char in polish_small:
|
||||
new_word += char.upper()
|
||||
elif char in polish_big:
|
||||
new_word += char.lower()
|
||||
else:
|
||||
new_word += char
|
||||
line = line.replace(to_replace, new_word, 1)
|
||||
print(line)
|
||||
final.append(line)
|
||||
|
||||
with open('polish_wiki_excerpt.out', 'w', encoding='utf8') as file:
|
||||
for line in final:
|
||||
file.write(line + '\n')
|
||||
|
||||
### odpowiedź nie do końca pokrywa się z plikiem .exp w wyniku obecności znaków z niemieckiego alfabetu
|
File diff suppressed because one or more lines are too long
42
TaskD02/taskD2.py
Normal file
42
TaskD02/taskD2.py
Normal file
@ -0,0 +1,42 @@
|
||||
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)
|
||||
|
||||
if "Nikołaj Judenicz" in line:
|
||||
pass
|
||||
|
||||
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')
|
File diff suppressed because one or more lines are too long
32
TaskD03/taskD3.py
Normal file
32
TaskD03/taskD3.py
Normal file
@ -0,0 +1,32 @@
|
||||
import re
|
||||
|
||||
final = []
|
||||
|
||||
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
|
||||
lines = file.readlines()
|
||||
pattern = r"\b([A-ZĄĆĘŁŃÓŚŹŻ]+\w*)\b|\b([a-ząćęłńóśźż]+\w*)\b"
|
||||
|
||||
for line in lines:
|
||||
#line = line.strip()
|
||||
line = line.replace('\n', '')
|
||||
x = re.findall(pattern, line)
|
||||
|
||||
a = 0
|
||||
b = 0
|
||||
|
||||
if x:
|
||||
for words in x:
|
||||
if words[0] != '':
|
||||
matching = words[0]
|
||||
b += 1
|
||||
elif words[1] != '':
|
||||
matching = words[1]
|
||||
a += 1
|
||||
print(a, b)
|
||||
final.append([a, b])
|
||||
|
||||
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')
|
File diff suppressed because one or more lines are too long
18
TaskD04/taskD4.py
Normal file
18
TaskD04/taskD4.py
Normal file
@ -0,0 +1,18 @@
|
||||
import re
|
||||
|
||||
final = []
|
||||
|
||||
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
|
||||
lines = file.readlines()
|
||||
pattern = r'(\D*\d+\D+?)\d+(.*)'
|
||||
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
line = re.sub(pattern, r'\1\2', line, count=1)
|
||||
print(line)
|
||||
final.append(line)
|
||||
|
||||
with open('polish_wiki_excerpt.out', 'w', encoding='utf8') as file:
|
||||
for line in final:
|
||||
file.write(line + '\n')
|
File diff suppressed because one or more lines are too long
25
TaskD05/taskD5.py
Normal file
25
TaskD05/taskD5.py
Normal file
@ -0,0 +1,25 @@
|
||||
import re
|
||||
|
||||
final = []
|
||||
|
||||
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
|
||||
lines = file.readlines()
|
||||
pattern = r"(\W*[\wąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+\W+[\wąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+\W)[\wąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+"
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
|
||||
def replace_third_word(match):
|
||||
prefix = match.group(1)
|
||||
word_to_replace = match.group(0)[len(prefix):len(match.group(0))]
|
||||
replacement = 'x' * len(word_to_replace)
|
||||
return prefix + replacement
|
||||
|
||||
line = re.sub(pattern, replace_third_word, line)
|
||||
print(line)
|
||||
|
||||
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')
|
16
checker.py
Normal file
16
checker.py
Normal file
@ -0,0 +1,16 @@
|
||||
with open("./TaskD01/polish_wiki_excerpt.out", 'r', encoding='utf8') as f:
|
||||
lines1 = f.readlines()
|
||||
|
||||
with open("./TaskD01/polish_wiki_excerpt.exp", 'r', encoding='utf8') as f:
|
||||
lines2 = f.readlines()
|
||||
|
||||
i = 1
|
||||
for line1, line2 in zip(lines1, lines2):
|
||||
if line1.strip() == line2.strip():
|
||||
pass
|
||||
# print('hurray')
|
||||
else:
|
||||
print(f'{i}: bad: \n{line1}{line2}')
|
||||
i += 1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user