Guest User

Untitled

a guest
May 26th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. def find_Positions_Word(text,word):
  2. p=text.find(word)
  3. if p<0 :
  4. print "The word "+word+" is not exist in this text"
  5. return 0
  6. else:
  7. list_position=[]
  8. list_position.append(p)
  9. while p>=0:
  10. p=text.find(word,p+1)
  11. if p>=0:
  12. list_position.append(p)
  13. print "The word "+word+" is repated " + str(len(list_position)) +" times in this text"
  14. print "The position of this word in the text at :"
  15. print list_position
  16. return len(list_position)
  17.  
  18.  
  19. t='''Hello ! every on ! i am python, i like every body use python , python is beautiful ,
  20. python is habby ,Good luck python'''
  21. n1=find_Positions_Word(t,'python')
  22. t1=t.replace('python','Java',n1)
  23. print t1
  24. print"------------------------"
  25. t2="I am learning the programming with python"
  26. n2=find_Positions_Word(t2,'python')
  27. t22=t2.replace('python','Java',n2)
  28. print t22
  29. print"------------------------"
  30. t3="Save the world"
  31. find_Positions_Word(t3,'python')
Add Comment
Please, Sign In to add comment