diff options
| author | Santiago Leyva <99155189+DevSanti12@users.noreply.github.com> | 2024-07-25 23:57:49 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-25 23:57:49 -0500 |
| commit | db40d75f603f3fae34944cb3a762b290b18577d8 (patch) | |
| tree | 1205c733ae416bcbce12e225a5252841316c5540 /challenge-279/steven-wilson/python/ch-2.py | |
| parent | 350f495b09a4b6b6db8506533e2dccc68d9fc3f4 (diff) | |
| parent | 3d6cbce024396f3950dad9b40151458e4134202d (diff) | |
| download | perlweeklychallenge-club-db40d75f603f3fae34944cb3a762b290b18577d8.tar.gz perlweeklychallenge-club-db40d75f603f3fae34944cb3a762b290b18577d8.tar.bz2 perlweeklychallenge-club-db40d75f603f3fae34944cb3a762b290b18577d8.zip | |
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-279/steven-wilson/python/ch-2.py')
| -rw-r--r-- | challenge-279/steven-wilson/python/ch-2.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-279/steven-wilson/python/ch-2.py b/challenge-279/steven-wilson/python/ch-2.py new file mode 100644 index 0000000000..0b9478b238 --- /dev/null +++ b/challenge-279/steven-wilson/python/ch-2.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +from pprint import pprint + + +def split_string(string, print_strings=False): + """ Given a string, split the given string into two containing exactly same + number of vowels and return true if you can otherwise false. + >>> split_string("perl") + False + >>> split_string("book") + True + >>> split_string("good morning") + True + """ + if len(string) < 2: + return False + + position_vowels = [i for i, c in enumerate(string) if c.casefold() in 'aeiou'] + + if not len(position_vowels) % 2 == 0: + return False + + if print_strings: + if len(position_vowels) < 2: + (start, stop) = (0, len(string)-1) + else: + split_index = int(len(position_vowels)/2) - 1 + (start, stop) = (position_vowels[split_index], position_vowels[split_index+1]) + pprint([(string[:i+1], string[i+1:]) for i in range(start, stop)]) + + return True + + +if __name__ == "__main__": + import doctest + + doctest.testmod(verbose=True) |
