Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. # funzione find (primo esercizio)
  2.  
  3. def find(str,searched,startIndex,endIndex):
  4. # @param str: str
  5. # @param searched
  6. # @param startIndex,endIndex: int; where to search for the 'searched' str
  7. # @return bool
  8. strValida= str[startIndex:endIndex]
  9. if appartenenza(strValida,searched):
  10. return true
  11. else:
  12. return false
  13.  
  14. def appartenenza(str,searched):
  15. # @param str: str; where to find 'searched'
  16. # @param searched: str; what to search for in 'str'
  17. # @return bool
  18. for j in range(len(str)):
  19. if searched[0]==str[j]:
  20. if caratteriSuccessivi(str, searched,j):
  21. return true
  22. return false
  23.  
  24. def caratteriSuccessivi(str, searched, strIndex):
  25. # @param str: str
  26. # @param searched: str
  27. # @param strIndex: int
  28. # @return bool
  29. newStr = str[strIndex+1:]
  30. for i in range(0,len(searched)-1):
  31. # questo if serve nel caso newStr finisca prima di searched. Ometterlo potrebbe far fallire la funzione
  32. if (i==len(newStr) and i!=len(searched)):
  33. return false
  34. if not searched[i+1]==newStr[i]:
  35. return false
  36. else:
  37. print 'loading'
  38. print strIndex
  39. return true
  40.  
  41. # sostituire ricorrenze con * (secondo esercizio)
  42.  
  43. def sostituireRicorrenze(str):
  44. # @param str: str
  45. for i in range(len(str)):
  46. for k in range(i+1,len(str)):
  47. if str[k]=='*':
  48. pass
  49. elif str[k]==' ':
  50. pass
  51. elif str[i]==str[k]:
  52. str = str[:k] + '*' + str[k+1:]
  53. else:
  54. pass
  55. return str
  56.  
  57. # verifica palindromo (terzo esercizio)
  58.  
  59. def verificaPalindromo(str):
  60. # @param str: str
  61. for i in range(len(str)/2):
  62. if not str[i]==str[len(str)-1-i]:
  63. return false
  64. return true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement