Last active
August 20, 2020 02:39
-
-
Save cassiasamp/4ba71e3b647f85f41c6dc49d5d7df40d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open('texto.txt', encoding='utf8') as file: | |
text = file.read() | |
cleaned_words = text.replace('.', ' ').replace('\n', ' ').replace('?', '').replace('(', '').replace(')', '').replace(',', ' ').split(' ') | |
dedup_words = list(set(cleaned_words)) | |
sorted_words = sorted(dedup_words, key=len, reverse=True) | |
first_ten_words = sorted_words[:10] | |
print('Ten longest words in file:', first_ten_words) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment