I tried 'abc'.split() to get ['a' ,'b', 'c'] as output but the output is ['abc'] , why and how can I get my desired output ? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

I tried 'abc'.split() to get ['a' ,'b', 'c'] as output but the output is ['abc'] , why and how can I get my desired output ?

21st Nov 2019, 8:09 PM
Ankur Singh Oli
Ankur Singh Oli - avatar
6 Respostas
+ 7
Since there is no seperator in the string you provided, and split takes two parameter, one seperator second number of max split.. so split won't work here.. u can try this: list('abc') would return ['a','b','c']
21st Nov 2019, 8:17 PM
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ 
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ  - avatar
+ 7
Another version: print('abc'.replace('',', '))
21st Nov 2019, 8:38 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 5
Print('a,b,c'.split(",")) And out put is ['a','b','c']
22nd Nov 2019, 8:25 AM
Abhishek
Abhishek - avatar
+ 4
Rik Wittkopp, wow, you can substitute nothing against something? That's funny. šŸ˜‚ And interesting, didn't know that!
21st Nov 2019, 9:34 PM
HonFu
HonFu - avatar
+ 3
Sami Khan thanks for explaining why it was not working and how it can be done by simply converting it into a list.
21st Nov 2019, 8:36 PM
Ankur Singh Oli
Ankur Singh Oli - avatar
+ 3
HonFu Wish I could do the same with my income. šŸ¤£
22nd Nov 2019, 9:30 AM
Rik Wittkopp
Rik Wittkopp - avatar