aboutsummaryrefslogtreecommitdiff
path: root/challenge-331/sgreen/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-331/sgreen/python/ch-1.py')
-rwxr-xr-xchallenge-331/sgreen/python/ch-1.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-331/sgreen/python/ch-1.py b/challenge-331/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..272f25d770
--- /dev/null
+++ b/challenge-331/sgreen/python/ch-1.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+
+import re
+import sys
+
+
+def last_word(input_string: str) -> int:
+ # Find the last word in the input string and return its length
+ match = re.search(
+ r"([a-z'-]*[a-z])[^a-z]*$",
+ input_string.strip(),
+ re.IGNORECASE
+ )
+ return len(match.group(1)) if match else 0
+
+
+def main():
+ result = last_word(sys.argv[1])
+ print(result)
+
+
+if __name__ == '__main__':
+ main()