blob: 5a47c5526eb24dc8664249890cebd743ec836146 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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 for word in args]
initialism = initialise(words)
print (initialism)
if __name__ == '__main__':
main()
|