Created
March 4, 2020 05:41
-
-
Save Eligijus112/4c38cdaf036e2588912d88dde514dd91 to your computer and use it in GitHub Desktop.
Creates a unique word dictionary using from a list of strings
This file contains hidden or 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
| def create_unique_word_dict(text:list) -> dict: | |
| """ | |
| A method that creates a dictionary where the keys are unique words | |
| and key values are indices | |
| """ | |
| # Getting all the unique words from our text and sorting them alphabetically | |
| words = list(set(text)) | |
| words.sort() | |
| # Creating the dictionary for the unique words | |
| unique_word_dict = {} | |
| for i, word in enumerate(words): | |
| unique_word_dict.update({ | |
| word: i | |
| }) | |
| return unique_word_dict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment