I already received an answer for the following question below. Unfortunately, not all the possible answers were checked. When I try the code in the tester it was getting hung up on a list that didn't have anything [] and a list that had [-150, -650, 353]. I was able to add the code to account for an empty list and a list that has 1 item.
I already received an answer for the following question below. Unfortunately, not all the possible answers were checked. When I try the code in the tester it was getting hung up on a list that didn't have anything [] and a list that had [-150, -650, 353].
I was able to add the code to account for an empty list and a list that has 1 item.
Thank you in advance for you assistance. The question originally asked is below.
Count dominators
def count_dominators(items):An element of items is said to be a dominator if every element to its right (not just the one element that is immediately to its right) is strictly smaller than it. By this definition, the last item of the list is automatically a dominator. This function should count how many elements in items are dominators, and return that count. For example, dominators of [42, 7, 12, 9, 13, 5] would be the elements 42, 13 and 5.
Before starting to write code for this function, you should consult the parable of "Shlemiel the painter" and think how this seemingly silly tale from a simpler time relates to today's computational problems performed on lists, strings and other sequences. This problem will be the first of many that you will encounter during and after this course to illustrate the important principle of using only one loop to achieve in a tiny fraction of time the same end result that Shlemiel achieves with two nested loops. Your workload therefore increases only linearly with respect to the number of items, whereas the total time of Shlemiel’s back-and-forth grows quadratically, that is, as a function of the square of the number of items.
items |
Expected result |
[42, 7, 12, 9, 2, 5]
|
4 |
[] |
0 |
[99] |
1 |
[42, 42, 42, 42]
|
1 |
range(10**7)
|
1 |
range(10**7, 0, -1)
|
10000000 |
[-150, -650, 353]
|
1 |
Trying to hide the inner loop of some Shlemiel
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)