comparison python/a8e.py @ 81:51a6ec0433f7

adding abbreviation program
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 30 Jun 2010 09:34:46 -0700
parents
children a7857000e206
comparison
equal deleted inserted replaced
80:413945f4c18b 81:51a6ec0433f7
1 #!/usr/bin/env python
2
3 import sys
4 import urllib2
5
6 def a8e(text):
7 text = text.split()
8 retval = []
9 for word in text:
10 if len(word) < 4:
11 retval.append(word)
12 else:
13 retval.append(word[0] + '%d' % (len(word) - 2) + word[1])
14 return ' '.join(retval)
15
16 def main(args=sys.argv[1:]):
17 if len(args) == 1 and (args[0].startswith('http://')
18 or args[0].startswith('https://')):
19 text = urllib2.urlopen(args[0]).read()
20 else:
21 text = ' '.join(args)
22 # TODO: read from stdin if no args
23 print a8e(text)
24
25 if __name__ == '__main__':
26 main()
27