aboutsummaryrefslogtreecommitdiff
path: root/challenge-096/tyler-wardhaugh/python/ch1.py
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-01-21 01:54:35 +0000
committerGitHub <noreply@github.com>2021-01-21 01:54:35 +0000
commit878d7ba2b2e95df8d0d59caa63019c1ac8cd198f (patch)
tree8335b89b59173681dc8ee0fe75c74fd79824861c /challenge-096/tyler-wardhaugh/python/ch1.py
parent56877338c2addcd41e2a8685b205f505963827b2 (diff)
parentd803b8295cb052657601c0f90392afac7b5fde47 (diff)
downloadperlweeklychallenge-club-878d7ba2b2e95df8d0d59caa63019c1ac8cd198f.tar.gz
perlweeklychallenge-club-878d7ba2b2e95df8d0d59caa63019c1ac8cd198f.tar.bz2
perlweeklychallenge-club-878d7ba2b2e95df8d0d59caa63019c1ac8cd198f.zip
Merge pull request #3328 from tylerw/tw/challenge-096
Challenge 096
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())