October 23rd, 2004, 11:00 PM
new to python, question regarding string
Well... I was trying to convert string into list of characters.
My job is to take the string and convert it to lowercase and sorted alphabetical order.
For example, if string "hash" is given, then I have to convert it into "ahhs"
So, I was looking for method something like "toArray" in Java which takes String and convert it into array list of characters, but I couldnt find one.
Is there anyway I can do this process without using any loops?
Please any help?
October 24th, 2004, 03:47 AM
You can use list(x) to convert any sequence to a list, or tuple(x) to turn a sequence to a tuple. Since a string is a sequence of characters, it will do what you want.
To do the reverse and convert a list of characters back into a string you need to use the string join method.
Dave - The Developers' Coach
>>> s = "Hello World"
>>> s = s.lower()
>>> l = list(s)
>>> print l
[' ', 'd', 'e', 'h', 'l', 'l', 'l', 'o', 'o', 'r', 'w']