Create is_good_str.py (#210)

* Create is_good_str.py

As discussed in #201

* Placate mypy

* Update README.md
pull/214/head
Christian Clauss 2021-04-16 14:29:58 +02:00 committed by GitHub
parent efc9eb7e94
commit 799fff7ecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View File

@ -25,5 +25,6 @@
4. [Selection Sort](sorting/selection_sort.py)
## Strings
1. [Palindrome](strings/palindrome.py)
2. [Word Count](strings/word_count.py)
1. [Is Good Str](strings/is_good_str.py)
2. [Palindrome](strings/palindrome.py)
3. [Word Count](strings/word_count.py)

View File

@ -0,0 +1,29 @@
# https://practice.geeksforgeeks.org/problems/good-or-bad-string1417/1/
from string import ascii_lowercase
vowels = "aeiou"
constants = "".join(c for c in ascii_lowercase if c not in vowels)
def is_good_str(s: str) -> bool:
"""
>>> is_good_str("aeioup??")
True
>>> is_good_str("bcdaeiou??")
False
"""
c_or_v = ""
for char in s.lower():
if char in constants:
c_or_v += "c"
else:
c_or_v += "v" if char in vowels else char
return not "c" * 4 in c_or_v.replace("?", "c") and (
not "v" * 6 in c_or_v.replace("?", "v")
)
if __name__ == "__main__":
print(is_good_str("aeioup??"))
print(is_good_str("bcdaeiou??"))