My string is:
"This is a string"
I want to turn it into a list:
["This", "is", "a", "string"]
I use the split(" ")
method, but it adds whitespaces as list elements. Please help,
Best Regards
My string is:
"This is a string"
I want to turn it into a list:
["This", "is", "a", "string"]
I use the split(" ")
method, but it adds whitespaces as list elements. Please help,
Best Regards
>>> v="This is a string"
>>> v.split()
['This', 'is', 'a', 'string']
just use split()
.
It won't add whitespace as elements if you just use .split()
, instead of .split(' ')
>>> "This is a string".split()
['This', 'is', 'a', 'string']
Like the docs say, don't pass an argument.
>>> "This is a string".split()
['This', 'is', 'a', 'string']