How to split string into list? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

How to split string into list?

I tried .split command,buts it's not working

31st Jan 2017, 1:15 AM
Akshay
Akshay - avatar
3 ответов
+ 1
Remember the split function returns a list, so you have to store that returned value into a variable. var = "this is a string" alist = var.split() print(alist) This will create a list from the string and because we didn't pass in any arguments into the split function it'll split based off of white space.
31st Jan 2017, 2:28 AM
Don
Don - avatar
+ 1
to split the string and place all characters into a list, u can use the list() function: my_var = "my string" my_list = list(my_var) print(my_list) #output: ['m', 'y', ' ', 's', 't', 'r', 'i', 'n', 'g']
2nd Feb 2017, 6:14 AM
Mr. M
Mr. M - avatar
0
a=['a'.......'z'] b=['p','l'i=j=0 while j <2 if a [i]=b [j] k=0 while k <26 b [j]=a [i+k ] print (b[j]) k=k+1 i=i+1 j=j+1
31st Jan 2017, 2:30 AM
Akshay
Akshay - avatar