return len of list without changing the method that returns index of list
<p>How can write a function outside of this class that will return the len of the list without modifying the class at all. </p>

<pre><code>class SingleMethodList(object):
    def __init__(self, l):
        self._list = l

    def get(self, index):
        try:
            return self._list[index]
        except IndexError:
            return None
</code></pre>

<p>I have tried to do the following, however, I am only allowed to use the get function. The reason for not modifying the class is because it is a challenge, </p>

<pre><code> def list_length(single_method_list):
     return len(single_method_list._list)
</code></pre>

<p>The challenge is taken from <a href="https://github.com/shipperizer/crowdscores#problem-2-list-length" rel="nofollow">here</a>:</p>

<p><em>You are given a list implementation, aptly named <code>SingleMethodList</code>. This list contains only one method:</em></p>

<pre><code>class SingleMethodList(object):

    def get(self, index):
        """ Returns the list item at `index`, otherwise returns None. """
        ...
</code></pre>

<p><em>You are required to calculate the length of this list, but due to immense beaurocratic restrictions at OmniCorp, you are not allowed to modify the interface of this class and you have to use it as is.</em></p>

<p><em>For this task you need to write a function <code>list_length(single_method_list)</code> that takes a <code>SingleMethodList</code> instance and returns its length. You may assume that no list will contain <code>None</code> as an item.</em></p>

<p>You can simply use a function like this in order to iterate through the list until you reach the end of it:</p>

<pre><code>def get_single_method_list_length(list_to_check):
    check_index = 0
    while list_to_check.get(check_index) is not None:
        check_index += 1
    return check_index # This will be the length of the list

test_list = SingleMethodList(range(50)) # an example list of length 50

print(get_single_method_list_length(test_list))
</code></pre>

<p>This prints out <code>50</code>, as it should. However, if your list has <code>None</code>s in it, the code will fail.</p>

python