[Solved] How do you count the values in a 2d list [closed]


You can use list comprehensions to do this. In this case, you can check the len of each sublist, and use that to filter out which sublists you want to keep/discard.

>>> df = [[2,4,6,7],[3,4,],[2,4,6,8,12,24],[3,5,7,333,450],[4,20]]
>>> [i for i in df if len(i) > 3]
[[2, 4, 6, 7], [2, 4, 6, 8, 12, 24], [3, 5, 7, 333, 450]]
>>> [i for i in df if len(i) == 2]
[[3, 4], [4, 20]]

0

solved How do you count the values in a 2d list [closed]