Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- text="ACTGTCAAACTATCGACAGACTGACTCGTAGAGCGTAGAGGGAGCTAGAGAGACGCGAGAGAGAGAGAGAGAGAGAGAAG"
- text="#"+"#".join(text)+"#" #add the junk characters
- length=len(text)
- lengthofslice=0
- longestslice=""
- for n in range(0,length): #iterate over every index in the text
- t=0 #t will be the variable that determines how many characters in the string we are looking "outward" from
- while(True):
- lowerbound=n-t
- if lowerbound<0: #we don't want our lower bound to go to the other end of the text
- break
- upperbound=n+t
- if upperbound>=length: #similarly here, we don't want an out of bound error
- break
- if text[lowerbound]==text[upperbound]: #check the characters
- if (upperbound-lowerbound)>lengthofslice:
- longestslice=text[lowerbound:upperbound+1] #take the slice
- lengthofslice=upperbound-lowerbound
- else:
- break
- t=t+1 #if we found a palindrome, increase the bounds to see if it continues
- longestslice=longestslice.replace("#","") #take out the junk characters
- print(longestslice)
- print(len(longestslice))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement