What I was trying to do:
Take a string and append a backwards copy of that string, making a palindrome
What I came up with:
# take an input string
a = input('Please enter a string: ')
a = list(a)
# read the string backwards
b = list(reversed(a))
# append the backward-ordered string to the original string, and print this new string
c = a + b
c = str(c)
print(c)
Question: When given a run, this script takes a string, for example "test", and returns ['t', 'e', 's', 't', 't', 's', 'e', 't']; I'm confused about this result since I explicitly converted c, as a result of concatenation of a and b, to a string. (c = str(c)) I know I must have missed some basic stuff here, but I wasn't able to figure out what. Could someone throw some light on this? Thank you!
And would anyone care to elaborate on why my c = str(c) didn't work? Thanks!
a = list(a)here. A string is already a sequence of characters, and you can already callreversedon it.ais set to be a string, would one be able to concatenate it withb? (i'm thinking aboutb=list(reversed(a))here), or is there another way (likeb=reversed(a)? can you do that?)b=reversed(a)instead ofb=a[::-1], then you will have tojoinupb, just as in nrpeterson's answer. Compactly:a + ''.join(reversed(a)). You may find that more readable thana + a[::-1], even though it requires some extra converting—if so, always go for the more readable version.