Created
October 2, 2016 14:01
-
-
Save anddam/8588e6a19a6f13056cc45b517b378195 to your computer and use it in GitHub Desktop.
Find unique words in a sentence and mark their positions
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
import string | |
sentence = input("Please enter a sentence \n") | |
translator = str.maketrans({key: None for key in string.punctuation}) | |
words = sentence.translate(translator).lower().split() | |
def indices(source_list, item): | |
return [index for index, value in enumerate(source_list) if value == item] | |
indexed_words = {word: indices(words, word) for word in set(words)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment