Jan-14-2019, 09:48 PM
Hi, I got a problem this code :
It works.
If I add a string at the end of the list, for example : ["a",["b","6"],"e",["5",["g","h"]],"i","o"], it works.
But when I add a sub list, for example : ["a",["b","6"],"e",["5",["g","h"]],"i",["k"]], I have a TypeError.
I don't understand why, could you please help me ?
def deepconcat(l) : if l == [] : return None elif len(l) == 1 : return l[0] else : for i in l : if type(i) == str : return l[0] + deepconcat(l[1:]) if type(i) == list : return deepconcat(i+l[1:])I have to turn ["a",["b","6"],"e",["5",["g","h"]],"i"] into "ab6e5ghi".
It works.
If I add a string at the end of the list, for example : ["a",["b","6"],"e",["5",["g","h"]],"i","o"], it works.
But when I add a sub list, for example : ["a",["b","6"],"e",["5",["g","h"]],"i",["k"]], I have a TypeError.
I don't understand why, could you please help me ?