Example
txt = "Python is great and it is simple."
txt.find("is")
The output is 7 but how to find out the next "is" word?
If there are many similar words, how to find them all?
Example
txt = "Python is great and it is simple."
txt.find("is")
The output is 7 but how to find out the next "is" word?
If there are many similar words, how to find them all?
Last edited by DrivingMobileInnovation; 2008-06-07 at 00:58.
An improvised solution could be like this:
Code:txt="Python is great and it is simple." #The text in which to search word="is" #The word to search for length=2 #The length of the word p=[] for i in range(len(txt)-length): if(txt[i:i+length]==word):p.append(i) #Append the position to the list print p
For core Python related issues, please refer to the documentation,
http://docs.python.org/tut/tut.html
Best Regards,
Croozeus
Pankaj Nathani
www.croozeus.com