0

How can I take a string such as "hello world" and turn it into a list of its chars?

I have some code that managed to work but I'm wondering if there's a more efficient way that involves less code.

Here's what I have:

stringOne = "Hello World" 
stringOneList = []

for i in stringOne:
    stringOneList.append(i)

print(stringOneList)

this results in an output of ['h','e','l','l','o',' ','w','o','r','l','d'] which IS what I'm after. But it feels clunky. Is there a function I'm missing that would do this more efficiently?

A. Miranda
  • 33
  • 3
  • `list("Hello World")`. – Abdou Nov 26 '17 at 20:28
  • 2
    Possible duplicate of [How to split a string into array of characters?](https://stackoverflow.com/questions/4978787/how-to-split-a-string-into-array-of-characters) – Abdou Nov 26 '17 at 20:33

1 Answers1

2
examplestring = "asdfg"

a = list(examplestring)

print(a)

gives:

['a', 's', 'd', 'f', 'g']
monamona
  • 1,195
  • 2
  • 17
  • 43