X 1 3 1 2 9 3 6 Hello Count Number Numbers Whole List Lists Example List X Two 1 One 2 Two Q37039362

x = [[1, 3], [1, 2, 9], [3, 6]]

Hello, how should I do to,count the number of each numbers inthe whole list of lists?

for example, in the list x, there is two of 1, one of 2, two of3, one of 6, one of 9?

please help in python


Solution


x = [[1, 3], [1, 2, 9], [3, 6]]d = {}for l in x: for num in l: if num not in d: d[num] = 0

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.