diff options
Diffstat (limited to 'challenge-279/packy-anderson/python')
| -rwxr-xr-x | challenge-279/packy-anderson/python/ch-1.py | 36 | ||||
| -rwxr-xr-x | challenge-279/packy-anderson/python/ch-2.py | 21 |
2 files changed, 57 insertions, 0 deletions
diff --git a/challenge-279/packy-anderson/python/ch-1.py b/challenge-279/packy-anderson/python/ch-1.py new file mode 100755 index 0000000000..f7fa18508d --- /dev/null +++ b/challenge-279/packy-anderson/python/ch-1.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +def sortLetters(letters, weights): + letterDict = dict(zip(weights, letters)) + return (''.join([ + letterDict[k] for k in sorted(letterDict.keys(), key=int) + ])) + +def comma_join(arr): + return ', '.join(map(lambda i: str(i), arr)) + +def solution(letters, weights): + print(f"Input: @letters = ('{ ', '.join(letters)}')") + print(f" @weights = ({comma_join(weights)})") + print(f'Output: {sortLetters(letters, weights)}') + +print('Example 1:') +solution( + ['R', 'E', 'P', 'L'], [3, 2, 1, 4] +) + +print('\nExample 2:') +solution( + ['A', 'U', 'R', 'K'], [2, 4, 1, 3] +) + +print('\nExample 3:') +solution( + ['O', 'H', 'Y', 'N', 'P', 'T'], [5, 4, 2, 6, 1, 3] +) + +print('\nExample 4:') +solution( + [ 'C', 'd', 'F', 'i', 'l', 'n', 'o', 'o', 's', 'u'], + [ 1, 4, 5, 8, 3, 10, 9, 2, 7, 6] +) diff --git a/challenge-279/packy-anderson/python/ch-2.py b/challenge-279/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..b0614bba56 --- /dev/null +++ b/challenge-279/packy-anderson/python/ch-2.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +vowels = ['a', 'e', 'i', 'o', 'u'] + +def splitString(str): + return len([ + v for v in list(str.lower()) if v in vowels + ]) % 2 == 0 + +def solution(str): + print(f'Input: @str = "{str}"') + print(f'Output: {splitString(str)}') + +print('Example 1:') +solution("perl") + +print('\nExample 2:') +solution("book") + +print('\nExample 3:') +solution("good morning") |
