0

I have

testlist = [[["a", "b", "c"]], [["a", "b", "c"], ["a", "b", "c"]]]

and want

finalist = [["a", "b", "c"], ["a", "b", "c"], ["a", "b", "c"]]

I've tried

finalist = [[item for subsublist in sublist for item in subsublist] for sublist in testlist]

but this gives me

finalist = [["a", "b", "c"], ["a", "b", "c", "a", "b", "c"]]
username
  • 75
  • 5
  • 3
    This is a common question and there's already a ton of detailed answers in this post: https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-a-list-of-lists I tested `list(itertools.chain(*testlist))` on your data and it does just what you want. – gavinb Apr 20 '21 at 03:20

1 Answers1

3

I tried this on your input. I think you just have to worry about the sublists and unpack them. Your approach is flattening sublists first which is why that last portion was wrong

[l for s in testlist for l in s]
Buckeye14Guy
  • 831
  • 6
  • 12