forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouredev.py
50 lines (33 loc) · 1.23 KB
/
mouredev.py
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
import re
from unidecode import unidecode
def __char_counter(text: str) -> dict[str, int]:
no_number_text = re.sub(r"\d+", "", text.lower().replace(" ", ""))
no_punt_text = re.sub(r"[^\w\s]", "", no_number_text)
# Obtenemos el unicode pero preservando la ñ
unicode = unidecode(no_punt_text.replace("ñ", ".")).replace(".", "ñ")
char_counter = dict()
for char in unicode:
if char in char_counter.keys():
char_counter[char] += 1
else:
char_counter[char] = 1
return char_counter
def isHeterogram(text: str) -> bool:
for counter in __char_counter(text).values():
if counter > 1:
return False
return True
def isIsogram(text: str) -> bool:
order = 0
for counter in __char_counter(text).values():
if order is 0:
order = counter
if order is not counter:
return False
return True
def isPangram(text: str) -> bool:
return len(__char_counter(text).keys()) is 27
print(isHeterogram("hiperblanduzcos"))
print(isHeterogram("hiperblanduzcós !!w"))
print(isIsogram("anna"))
print(isPangram("Benjamín pidió una bebida de kiwi y fresa. Noé, sin vergüenza, la más exquisita champaña del menú"))