Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_palin_iterative_from_recursive(s):
- """
- I created this version by transforming the recursive solution to
- an iterative one. In my tests its a bit faster then `is_plain_strrec`
- """
- s = str(s)
- while True:
- if not s:
- return True
- elif s[0] != s[-1]:
- return False
- else:
- s = s[1:-1]
- def is_palin_iterative_with_while(s):
- """
- Like the iterative version, but uses a while loop
- and thus avoids some of the overhead in the for-loop version
- """
- s = str(s)
- i = 0
- t = len(s) // 2
- while i < t:
- if s[i] != s[-(1+i)]:
- return False
- i += 1
- return True
Advertisement
Add Comment
Please, Sign In to add comment