this question has answer here:
- (python) adding list without brackets 3 answers
here i'm trying merge 2 lists, making 1 whit items.
n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]] def flatten(n): s=[] x in n: s.append(x) return s print flatten(n) i'm trying have result
[1,2,3,4,5,6,7,8,9] but i'm getting
[[1, 2, 3], [4, 5, 6, 7, 8, 9]] i dont understand why, think i'm assigning each value list 's' in loop.
you're appending list. each sublist appended new list own item, way originally. want extend list instead:
s.extend(x)
Comments
Post a Comment