This is my current progress. I'm somewhat new to Python and I'm kind of lost. I don't really know exactly how to solve the problem and I apologies if the title is somewhat misleading. I'll try and explain my problem as best I can.
The output needs to be this in list form:
"WHAT", "IS", "MINE", "IS", "YOURS", "AND", "WHAT", "IS", "YOURS", "IS", "MINE"
"1", "2", "3", "2", "4", "5", "1", "2", "4", "2", "3"
"1"
is "WHAT"
, "2"
is "IS"
... and so on. If the word appears more than once, it will remain the same number.
Code
sentence = "WHAT IS MINE IS YOURS AND WHAT IS YOURS IS MINE";
sentence = sentence.lower();
sentence = sentence.split();
uniqueWord = [];
store = [];
for i in sentence:
if i not in uniqueWord:
uniqueWord.append(i);
lengthOfUniqueWord = len(uniqueWord);
print(sentence);
print(uniqueWord);
for i in range(lengthOfUniqueWord):
i = str(i+1);
store.append(i);
print(store);
for positions in enumerate(uniqueWord, 1):
print(positions);
Output
['what', 'is', 'mine', 'is', 'yours', 'and', 'what', 'is', 'yours', 'is', 'mine']
['what', 'is', 'mine', 'yours', 'and']
['1', '2', '3', '4', '5']
(1, 'what')
(2, 'is')
(3, 'mine')
(4, 'yours')
(5, 'and')