A solution with dictionaries :
text="the sailor went to sea sea sea to see what he could see see see but all that he could see see see was the bottom of the deep blue sea sea sea"
l=text.split(' ')
d=dict()
cnt=0
for word in l :
if word not in d :
cnt+=1
d[word]=cnt
out=[d[w] for w in l]
#[1, 2, 3, 4, 5, 5, 5, 4, 6, 7, 8, 9, 6, 6, 6, 10, 11, 12, 8, 9, 6, 6, 6, 13, 1, 14, 15, 1, 16, 17, 5, 5, 5]