0
How to convert a paragraph in to a list of unique words and positions then to convert the positions back to the original para
I have so far got a list of unique words and positions but can't converts back to the original paragraph. If you don't fully understand the question please ask me to explain more clearly
2 odpowiedzi
+ 3
The inverse method is 'split()':
myStr = "This is Python"
myWords = myStr.split(" ")
print(myWords)
# output:
["This", "is", "Python"]
... so indexes are relative positions ( rank ) of words.
If you need accurate position ( ie position of first chart of each word in original string ), you can use method 'index()' ( be aware to this method return the first matching index ) and store the result... or look at regular expression, which can resolve that in one line, but is not easy stuff to learn, requiring lot of time to very progressively increase our skills ( more fast as you'll intensivelly practice, obviously ).
+ 1
If you are asking how to convert a list of string back to a sentence then you can do it by using .join().
myStr = ["This","is","python"]
myStr2 = " ".join(myStr)
print (myStr2 )