Through searching similar questions I've found how to use in
to check if a list contains a specific element. But I wasn't able to find how to check and count if an element exists within a certain range of a list.
Example:
Inventory = [1, 2, 3, 5, 1, 2, 3, 3, 5, 0, 1, 5, 3, 6, 1, 0, 2, 4, 2, 8]
In the list there are 20 elements and 2 instances of 0
. I'd like to count how many instances of zero are contained within every 5 elements with an output similar to this:
Elements 1–5 contain 0 zeroes.
Elements 6-10 contain 1 zeroes.
Elements 11-15 contain 0 zeroes.
Elements 16-20 contain 1 zeroes.
Any help is very much appreciated.