Sunday, August 25, 2013

Flattening a list of strings, got a solution but don't know why this works

Flattening a list of strings, got a solution but don't know why this works

Sorry for the vague question, but it's because I really don't understand
why this works the way it does. I found a solution for my problem here.
The thing is, my answer was exactly the same, except for (checkio(x)), I
had just (x).
So instead of this (working solution):
def checkio(data):
new_list = []
for x in data:
if type(x) == list:
new_list.extend(checkio(x))
else:
new_list.append(x)
return new_list
I had:
def checkio(data):
new_list = []
for x in data:
if type(x) == list:
new_list.extend(x)
else:
new_list.append(x)
return new_list
Why doesn't that work? Why do I need to reference to the function itself?
What is checkio(x) exactly?

No comments:

Post a Comment