Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. text="ACTGTCAAACTATCGACAGACTGACTCGTAGAGCGTAGAGGGAGCTAGAGAGACGCGAGAGAGAGAGAGAGAGAGAGAAG"
  2. text="#"+"#".join(text)+"#" #add the junk characters
  3. length=len(text)
  4. lengthofslice=0
  5. longestslice=""
  6. for n in range(0,length): #iterate over every index in the text
  7.     t=0  #t will be the variable that determines how many characters in the string we are looking "outward" from
  8.     while(True):
  9.         lowerbound=n-t
  10.         if lowerbound<0: #we don't want our lower bound to go to the other end of the text
  11.             break
  12.         upperbound=n+t
  13.         if upperbound>=length: #similarly here, we don't want an out of bound error
  14.             break
  15.         if text[lowerbound]==text[upperbound]: #check the characters
  16.             if (upperbound-lowerbound)>lengthofslice:
  17.                 longestslice=text[lowerbound:upperbound+1] #take the slice
  18.                 lengthofslice=upperbound-lowerbound
  19.         else:
  20.             break
  21.         t=t+1 #if we found a palindrome, increase the bounds to see if it continues
  22. longestslice=longestslice.replace("#","") #take out the junk characters
  23. print(longestslice)
  24. print(len(longestslice))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement