-3

Say I have a string like this

s="a b c de fgh"

Now I want to convert it to a list like this

list1=['a','b','c','de','fgh']

That is I will separate the characters when there's a space and make them a string of its own and store them in a list. Is there any easier way to do this in a single line command or so rather than iterating over the string and break it up and add it to the list whenever a space is found?

Turing101
  • 347
  • 3
  • 15

1 Answers1

1

split does exactly that:

result = s.split()
Mureinik
  • 297,002
  • 52
  • 306
  • 350