stringlistjythonjes

Is it possible to convert a String into a List data type?


Okay so, my code:

def isPalindrome():
  string = requestString("give me a Palendrom!, add spaces between each letter")
  list = string.split()
  print list
  reverseList = list.reverse()
  print reverseList

this is unfinished, but the idea is to detect Palindromes, the user is to input a word and, what I want to be able to do is say.

if list = reverseList:
  print "yes"
else:
  print "no!"

But unfortunately the return from what I have is:

======= Loading Progam =======
>>> isPalindrome()
['r', 'a', 'd', 'a', 'r']
None
>>>

My class mates are taking a different approach to this question, but I have a reputation for 'unique' code, so I was hoping this would work.

My question is 1 is this even possible? 2 is there a better approach to this problem?

Side note, I am very new to this, I am using JES, Jython and this is my first question on stackoverflow, be kind :D

Edit:

def isPalindrome2():
  string = requestString("give me a Palindrome, make sure the letters are spaced")
  print string
  reversedString = string[::-1]
  print reversedString

  if string == reversedString:
    print ("this is a Palindrome")
  else:
    print ("this is not a Palindrome")

OutPut:

>>> isPalindrome2()
r a d a r
r a d a r
this is a Palindrome

Solution

  • string[::-1]
    

    It should return the string reversed.