diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-01-21 01:54:35 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-21 01:54:35 +0000 |
| commit | 878d7ba2b2e95df8d0d59caa63019c1ac8cd198f (patch) | |
| tree | 8335b89b59173681dc8ee0fe75c74fd79824861c /challenge-096/tyler-wardhaugh/python/ch1.py | |
| parent | 56877338c2addcd41e2a8685b205f505963827b2 (diff) | |
| parent | d803b8295cb052657601c0f90392afac7b5fde47 (diff) | |
| download | perlweeklychallenge-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-x | challenge-096/tyler-wardhaugh/python/ch1.py | 25 |
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()) |
