oyouareatubeo

Analayze Da Tubes

Dec 11th, 2011
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys
  4. import subprocess as sub
  5.  
  6.  
  7. def wordList(input):
  8.     popCloud = ( "cat %s |"
  9.                  "tr -cs A-Za-z '\n' |"
  10.                  "tr A-Z a-z |"
  11.                  "sort |"
  12.                  "uniq -c |"
  13.                  "sort -rn"
  14.                  % (input)
  15.                )
  16.  
  17.     p = sub.Popen( popCloud, shell=True, stdout=sub.PIPE, stderr=sub.PIPE )
  18.     output, errors = p.communicate()
  19.     return [word.strip() for word in output.split('\n')]
  20.  
  21. def wordDict(wordList):
  22.     wordDict = {}
  23.     for w in wordList:
  24.         if len(w) > 4:
  25.             k,v = w.split(' ')
  26.             wordDict[v] = k
  27.     return wordDict
  28.  
  29. def rmShortWords(wordList,length):
  30.     li = []
  31.     for p, w in enumerate(wordList):
  32.         if len(w.split(' ')[-1]) >= length:
  33.             li.append(w)
  34.     return li
  35.  
  36. def main():
  37.     list = wordList(sys.argv[1])
  38.     dictionary = wordDict(list)
  39.     shortList = rmShortWords(list,20)
  40.     print shortList
  41.  
  42. if __name__ == "__main__":
  43.     main()
  44.                                                                            
  45.  
Advertisement
Add Comment
Please, Sign In to add comment