Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # funzione find (primo esercizio)
- def find(str,searched,startIndex,endIndex):
- # @param str: str
- # @param searched
- # @param startIndex,endIndex: int; where to search for the 'searched' str
- # @return bool
- strValida= str[startIndex:endIndex]
- if appartenenza(strValida,searched):
- return true
- else:
- return false
- def appartenenza(str,searched):
- # @param str: str; where to find 'searched'
- # @param searched: str; what to search for in 'str'
- # @return bool
- for j in range(len(str)):
- if searched[0]==str[j]:
- if caratteriSuccessivi(str, searched,j):
- return true
- return false
- def caratteriSuccessivi(str, searched, strIndex):
- # @param str: str
- # @param searched: str
- # @param strIndex: int
- # @return bool
- newStr = str[strIndex+1:]
- for i in range(0,len(searched)-1):
- # questo if serve nel caso newStr finisca prima di searched. Ometterlo potrebbe far fallire la funzione
- if (i==len(newStr) and i!=len(searched)):
- return false
- if not searched[i+1]==newStr[i]:
- return false
- else:
- print 'loading'
- print strIndex
- return true
- # sostituire ricorrenze con * (secondo esercizio)
- def sostituireRicorrenze(str):
- # @param str: str
- for i in range(len(str)):
- for k in range(i+1,len(str)):
- if str[k]=='*':
- pass
- elif str[k]==' ':
- pass
- elif str[i]==str[k]:
- str = str[:k] + '*' + str[k+1:]
- else:
- pass
- return str
- # verifica palindromo (terzo esercizio)
- def verificaPalindromo(str):
- # @param str: str
- for i in range(len(str)/2):
- if not str[i]==str[len(str)-1-i]:
- return false
- return true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement