-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·63 lines (44 loc) · 1.45 KB
/
main.py
File metadata and controls
executable file
·63 lines (44 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def is_palindorme(text: str) -> bool:
is_palindorme: bool = True
for i, _ in enumerate(text):
if text[i-1] != text[-1*i]:
is_palindorme = False
break
return is_palindorme
def is_palindorme_simple(text: str) -> bool:
return text == text[::-1]
def sort(text: str, sort_type: str = 'asc') -> str:
sort_types = ('asc', 'desc')
if sort_type not in sort_types:
raise ValueError('Wrong sort type')
abc: str = 'abcdefghijklmopqrstuvwxyz'
if sort_type == 'desc':
abc = abc[::-1]
unique_text: set = set(text)
sorted_str: str = str()
# n**2
for letter in abc:
for char in unique_text:
if letter == char:
sorted_str += letter
continue
return sorted_str
def sort_utf(text: str, sort_type: str = 'asc'):
# Do setup
sort_types = ('asc', 'desc')
if sort_type not in sort_types:
raise ValueError('Wrong sort type')
unique_unicode_chars: set = set(ord(char) for char in text)
is_reversed = sort_type == 'desc'
# Do sort
sorted_chars = sorted(unique_unicode_chars, reverse=is_reversed)
# Do formatting
sorted_chars = [chr(char) for char in sorted_chars]
sorted_chars = ''.join(sorted_chars)
return sorted_chars
print("asc sort")
print(sort_utf("abcs"))
print(sort_utf("5543234"))
print(sort_utf("абцдabc23"))
print("desc sort")
print(sort_utf("abcdejj", sort_type="desc"))