aboutsummaryrefslogtreecommitdiff
path: root/challenge-278/packy-anderson/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-278/packy-anderson/python/ch-2.py')
-rwxr-xr-xchallenge-278/packy-anderson/python/ch-2.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-278/packy-anderson/python/ch-2.py b/challenge-278/packy-anderson/python/ch-2.py
new file mode 100755
index 0000000000..863bb90365
--- /dev/null
+++ b/challenge-278/packy-anderson/python/ch-2.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+def reverseWord(str, char):
+ pos = str.find(char)
+
+ # if the character isn't in the string, do nothing
+ if pos < 0: return str
+
+ parts = [ str[0:pos+1], str[pos+1:] ]
+
+ parts[0] = ''.join(sorted(list(parts[0])))
+
+ return ''.join(parts)
+
+def solution(str, char):
+ print(f'Input: $str = "{str}", $char = "{char}"')
+ print(f'Output: "{reverseWord(str, char)}"')
+
+print('Example 1:')
+solution("challenge", "e")
+
+print('\nExample 2:')
+solution("programming", "a")
+
+print('\nExample 3:')
+solution("champion", "b")