-3

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 .

  • 3
    Possible 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 Answers3

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
2
list(x)

OR

mylist = []
for c in x:
    mylist.append(c)
nobody
  • 10,892
  • 8
  • 45
  • 63