desdemona

mapper wc

May 1st, 2016
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import string
  5.  
  6. # input comes from STDIN (standard input)
  7. for line in sys.stdin:
  8.     # remove leading and trailing whitespace
  9.     line = line.strip()
  10.     # split the line into words
  11.     words = line.split()
  12.     # increase counters
  13.     for word in words:
  14.         # write the results to STDOUT (standard output);
  15.         # what we output here will be the input for the
  16.         # Reduce step, i.e. the input for this
  17.         #
  18.         # tab-delimited; the trivial word count is 1
  19.         if len(word) == 1:
  20.             continue
  21.  
  22.         for letter in word:
  23.             if letter in string.ascii_letters:
  24.                 print '%s\t%s' % (word, 1)
  25.                 break
Add Comment
Please, Sign In to add comment