Is palindrome?

 Today's AlgoDaily problem was checking whether a string is a palindrome, meaning whether it is the same backwards and forward. For example this string is a palindrome: 'A Santa Lived As a Devil At NASA':-D

I wrote a simple function that reverses the string. It iterates over the string and assigns its elements in a preallocated array (list). The trick is to assign the letters into len(string)-letter_index-1'th position in the preallcoated array. That way you are populating the array in reverse order. -1 is due to the Python indexing convention where the string starts at 0 and ends at len(str)-1. 

The code is here: https://github.com/mariakesa/Algorithms/blob/master/AlgoDaily/AlgorithmsPractice.ipynb

Kommentaarid