Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_Positions_Word(text,word):
- p=text.find(word)
- if p<0 :
- print "The word "+word+" is not exist in this text"
- return 0
- else:
- list_position=[]
- list_position.append(p)
- while p>=0:
- p=text.find(word,p+1)
- if p>=0:
- list_position.append(p)
- print "The word "+word+" is repated " + str(len(list_position)) +" times in this text"
- print "The position of this word in the text at :"
- print list_position
- return len(list_position)
- t='''Hello ! every on ! i am python, i like every body use python , python is beautiful ,
- python is habby ,Good luck python'''
- n1=find_Positions_Word(t,'python')
- t1=t.replace('python','Java',n1)
- print t1
- print"------------------------"
- t2="I am learning the programming with python"
- n2=find_Positions_Word(t2,'python')
- t22=t2.replace('python','Java',n2)
- print t22
- print"------------------------"
- t3="Save the world"
- find_Positions_Word(t3,'python')
Add Comment
Please, Sign In to add comment