changeset 81:51a6ec0433f7

adding abbreviation program
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 30 Jun 2010 09:34:46 -0700
parents 413945f4c18b
children a7857000e206
files python/a8e.py
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/a8e.py	Wed Jun 30 09:34:46 2010 -0700
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+import sys
+import urllib2
+
+def a8e(text):
+  text = text.split()
+  retval = []
+  for word in text:
+    if len(word) < 4:
+      retval.append(word)
+    else:
+      retval.append(word[0] + '%d' % (len(word) - 2) + word[1])
+  return ' '.join(retval)
+
+def main(args=sys.argv[1:]):
+  if len(args) == 1 and (args[0].startswith('http://')
+                         or args[0].startswith('https://')):
+    text = urllib2.urlopen(args[0]).read()
+  else:
+    text = ' '.join(args)
+  # TODO: read from stdin if no args
+  print a8e(text)
+
+if __name__ == '__main__':
+  main()
+