+ 2
String to list
Please is there anyway to change a string to a list?? E.g. file=("this is a sentence") so my question is that is there anyway to change file into a list with 'this' having index 0, 'is' with index 1 , 'a' with index 2 and 'sentence' with index 3
4 Respostas
+ 4
Yes, there is. You must use split like this:
file = "this is text"
l = file.split(" ")
print(l)
It will bring you what you want.
+ 3
if you have simple string without spaces like this.
x='man'
you can convert into list in very simple way using list function.
print(list(x)) #output=['m','a','n']
+ 2
def func(a):
print(a.split(" "))
func("this is some help")
0
sorry but does it work for an integer and how?