desdemona

better_wc_mapper

Jun 8th, 2016
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import string
  5.  
  6. def read_input(file):
  7.     printable = set(string.printable)
  8.  
  9.     for line in file:
  10.         line = filter(lambda x: x in printable, line)
  11.         line = line.strip()
  12.         yield line.lower().split()
  13.  
  14. def main(separator='\t'):
  15.     ascii_letters = set(string.ascii_letters)
  16.     data = read_input(sys.stdin)
  17.     for words in data:
  18.         for word in words:
  19.             word = filter(lambda x: x in ascii_letters, word)
  20.             word = str.strip(word)
  21.  
  22.             if len(word) == 1:
  23.                 continue
  24.  
  25.             print '%s\t%s' % (word, 1)
  26.  
  27. if __name__ == "__main__":
  28.     main()
Add Comment
Please, Sign In to add comment