-1

I know that a question similar to this has been asked before, but I want to ask this, which is slightly different:

Here is example: counts[[0,10,4,2], [0,0,0,0,5,7]]

If I wanted to count the number of a specific element, lets say 0 in a two dimensional array for one part of the array like counts[0], how would we do so? Trying to do things for project Euler q3. So like the example output here should be 1, if we did it for counts[1] which should give: 4.

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
  • 2
    Does this answer your question? [How can I count the occurrences of a list item?](https://stackoverflow.com/questions/2600191/how-can-i-count-the-occurrences-of-a-list-item) Writing "Not a duplicate" in the title does not make your question so. You still want to count the number of zeros in a one-dimensional list. The only difference now is that your list is accessed as `counts[0]` instead of at `mylist`. – Pranav Hosangadi May 24 '21 at 21:33

1 Answers1

0

You could just directly access the "part" of the list using its index like counts[0] and then call the python built-in list function count to count the appearances of the desired value:

counts = [[0, 10, 4, 2], [0, 0, 0, 0, 5, 7]]

print(counts[0].count(0))
print(counts[1].count(0))

# Output
1
4
schilli
  • 1,700
  • 1
  • 9
  • 17