python-palindrome-test

Quick ditty using Python to tell if a string is a palindrome.

is_palindrome.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/python
import sys

def is_palindrome(string):
t_f = False
string2 = ''
arr_tmp = []
rev_str = ''

#can use the for loop with slice notation
#or reversed() to reverse the string
for item in list(string)[::-1]:
arr_tmp.append(item)
# arr_tmp = list(reversed(string))

rev_str = string2.join(arr_tmp)

if string == rev_str:
t_f = True

print(t_f)

is_palindrome(sys.argv[1])