-1

I have a list of lists which contain different values and different lengths.

I want my code to iterate the "big list", and if an "item-list" (a sub-list in the big list) follows a condition (for example, len(list[i] > 1), I want to add this "item-list" to a new big list, so at the end, I will get a new list of lists (which all follow the condition).

The append() methoddoesn't work when I want to append a whole list.
Do you have any suggestion, how should I do it?

martineau
  • 119,623
  • 25
  • 170
  • 301
Mshar
  • 3
  • 1
  • 4

1 Answers1

0

The way to do it would be

new_big_list = [x for x in big_list if condition(x)]

but the loop with .append() should work if you start with an empty list

JMat
  • 752
  • 6
  • 14