aboutsummaryrefslogtreecommitdiff
path: root/challenge-096/tyler-wardhaugh/python/ch1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-096/tyler-wardhaugh/python/ch1.py')
-rwxr-xr-xchallenge-096/tyler-wardhaugh/python/ch1.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-096/tyler-wardhaugh/python/ch1.py b/challenge-096/tyler-wardhaugh/python/ch1.py
new file mode 100755
index 0000000000..37272382cb
--- /dev/null
+++ b/challenge-096/tyler-wardhaugh/python/ch1.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+"""Challenge 96, Task 1"""
+
+import sys
+import re
+
+DEFAULT_INPUT = "The Weekly Challenge"
+
+def reverse_words(s):
+ """Split a string s into words and reverse their order."""
+ words = re.split(r'\s+', s.strip())
+ return ' '.join(words[::-1])
+
+
+def main(args=None):
+ """Run the task"""
+ if args is None:
+ args = sys.argv[1:]
+
+ s = args[0] if args else DEFAULT_INPUT
+ print(reverse_words(s))
+
+
+if __name__ == '__main__':
+ sys.exit(main())