0

I want to remove empty list and extra [] around elements

Input: data = [[1], [], [2], [], [], [4]];
Expected: output = [1,2,4]

When I do this : d = [x for x in data if x] I have an output with [] around elements as below:

[[1], [2], [4]]

Appreciate if someone can help!

juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172
Sara
  • 33
  • 5

1 Answers1

1
from itertools import chain

print(list(chain(*data)))
Shirin Yavari
  • 626
  • 4
  • 6