DawidBellam DawidBellam - 3 months ago 10
Python Question

How do I have items in a list be correspondent to integers?

As the title says, how do I do that?

Answer

This should work:

sentence = "WHAT IS MINE IS YOURS AND WHAT IS YOURS IS MINE";    
sentence = sentence.lower();
sentence = sentence.split();

uniqueWord = [];

for i in sentence:
    if i not in uniqueWord:
        uniqueWord.append(i);

for word in sentence:
    print uniqueWord.index(word) + 1

Here it is the link to the documentation of index

Comments