+ 1
how to get this >>> explode("spam") ['s', 'p', 'a', 'm'] >>> explode(" ") [ ]
13 odpowiedzi
+ 3
>>> list("spam")
['s','p','a','m',]
>>> list("")
[]
+ 2
+ 2
Please stop just saying "It doesn't work" without giving any clue of the problem, it's irritating. We're not psychics, we can't read your mind. Please?
Could you copy/paste what you get and what you expect?
+ 1
def explode(s):
if not isinstance(s, str):
raise TypeError
chars = []
for c in s:
chars.append(c)
return chars
+ 1
How so?
0
There are something wrong, it doesnt work right
0
I dont know, that whys im asking you guys, I try to run your but it doesnt work the same the given output :(
0
Oh thats my fault, my question was unclear so your answer went to another way but you're right.
My qs is that explode(S) should take string as input and should return a list of characters in that string, so the qs was just a example of an output
0
I put that in to the python on my computer, it doesnt work, i dont know why
0
"Oh thats my fault, my question was unclear so your answer went to another way but you're right.
My qs is that explode(S) should take string as input and should return a list of characters in that string, so the qs was just a example of an output"
I still don't see how the explode() I defined is different from the one you asked for. Unless you mean that the list can't have repeated characters?
Giovanni nailed it btw, you can simply use list().
0
# remember the indentation
def explode(x):
list(x)
explode("spam")
explode("")
0
# even so
explode = list
explode("spam")
explode("")
0
# if, for any reason, you don't want to use 'list'
def explode(x):
c = [n for n in x]
return c
explode("spam")
explode("")