+ 1
I need this code I wrote to be further processed to give the exact value for of the result based on the comments
# a function to flatten a list. #The list contains other lists, #strings, or ints. e.g example, #[[1,'a',['cat'],2],[[[3]],'dog'],4,5] #is flattened into #[1,'a','cat',2,3,'dog',4,5] (order #matters). def flatten(aList): ''' aList: a list Returns a copy of aList, which is a flattened version ''' r=[] k=[] for item in aList: if type(item) is list: r.extend(flatten(item)) else: k.append(item) if k: r.insert(0,k) return r
2 odpowiedzi
+ 1
I love you
0
Thank you