How do I convert def stringParametre(x) x to a list so that if x is hello then it will become a list like ["H","E","l","l","O"] . Capitals don't matter .
Asked
Active
Viewed 138 times
-3
-
3Possible duplicate of [convert a string to an array](http://stackoverflow.com/questions/5387208/convert-a-string-to-an-array) – Vincent Orback Mar 09 '16 at 22:40
3 Answers
3
Note that you do not have to convert to a list if all you want to do is to iterate over the characters of the string:
for c in "hello":
# do something with c
works

Dimitri Merejkowsky
- 1,001
- 10
- 12
2
Building on @idjaw's comment:
def stringParametre(x):
return list(x)
Of course this will have an error if x
is not a string (or other sequence type).

John Gordon
- 29,573
- 7
- 33
- 58
-
correction: will raise an error if x is not iterable, will obviously not give desired results if x is not a `str` – Tadhg McDonald-Jensen Mar 09 '16 at 22:40