summaryrefslogtreecommitdiff
path: root/initialism.py
diff options
context:
space:
mode:
Diffstat (limited to 'initialism.py')
-rwxr-xr-xinitialism.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/initialism.py b/initialism.py
new file mode 100755
index 0000000..f94496b
--- /dev/null
+++ b/initialism.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+
+"""
+Take a list of words as argument and return the equivalent initialism.
+
+Example:
+ $ initialism got a cup of tea
+ $ GACOT
+"""
+
+import optparse
+import sys
+
+VERSION = '1.0.0'
+
+
+def parse_args():
+ args = sys.argv[1:]
+ if not args:
+ args = sys.stdin.read().split()
+
+ parser = optparse.OptionParser(usage='!initialism <word> [<word>]+ [-v|--version]')
+ parser.add_option('-v', '--version', action='store_true')
+ return parser.parse_args(args)
+
+
+def initialise( words ):
+ """
+ Take the first grapheme from each of the words and uppercase it
+ returning a new unicode string created from them.
+ """
+ return u''.join([word[0].upper() for word in words])
+
+
+def main():
+ (options, args) = parse_args()
+ if options.version:
+ print ('!initialism {0}'.format(VERSION))
+ sys.exit(0)
+
+ words = [word.decode('utf-8') for word in args]
+ initialism = initialise(words)
+ print (initialism.encode('utf-8'))
+
+
+if __name__ == '__main__':
+ main()