Here is my code,
userinput = input("Enter a sentence: ")
wordlist = userinput.split()
uniquelist = []
for word in wordlist:
if word not in uniquelist:
uniquelist.append(word)
print ("Here are the words in their first appearing index form: ")
my_indexes = ' '.join(str(uniquelist.index(word)+1) for word in wordlist)
print (uniquelist)
print (my_indexes)
It asks the user for an input, a sentence without punctuation, and the program return the positions of each word in that sentence. If any words occur more than once, it outputs the index position of the first time it occurred.
For eg: if the input was - "I like to code because to code is fun" . The output would be -
1 2 3 4 5 3 4 6 7
How would i convert the output, i guess its a string? I am not definite for sure hence the vague title - to a list which has the format
[1,2,3,4,5,3,4,6,7]
?