Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- import subprocess as sub
- def wordList(input):
- popCloud = ( "cat %s |"
- "tr -cs A-Za-z '\n' |"
- "tr A-Z a-z |"
- "sort |"
- "uniq -c |"
- "sort -rn"
- % (input)
- )
- p = sub.Popen( popCloud, shell=True, stdout=sub.PIPE, stderr=sub.PIPE )
- output, errors = p.communicate()
- return [word.strip() for word in output.split('\n')]
- def wordDict(wordList):
- wordDict = {}
- for w in wordList:
- if len(w) > 4:
- k,v = w.split(' ')
- wordDict[v] = k
- return wordDict
- def rmShortWords(wordList,length):
- li = []
- for p, w in enumerate(wordList):
- if len(w.split(' ')[-1]) >= length:
- li.append(w)
- return li
- def main():
- list = wordList(sys.argv[1])
- dictionary = wordDict(list)
- shortList = rmShortWords(list,20)
- print shortList
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment