Advertisement
robertvari

longestWord

Jan 18th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. # -*- coding:Utf-8 -*-
  2. with open("D:/tmp/The Adventures of Sherlock Holmes.txt") as f:
  3.     text = f.read()
  4.  
  5. wordDict = {}
  6.  
  7. for i in text.split(" "):
  8.     wordLen = len(i)
  9.     if not wordLen in wordDict:
  10.         wordDict[wordLen] = []
  11.  
  12.     wordDict[wordLen].append(i)
  13.  
  14. print [wordDict[n][0] for n in sorted(wordDict, reverse=True)][:3]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement