Stop writing classes
what is the purpose to write a class with the only purpose to return an element of a list that you pass as argument at the time of instantiation?
if that is some weird test question
what is the purpose to write a class with the only purpose to return an element of a list that you pass as argument at the time of instantiation?
if that is some weird test question
from single_method_list import SingleMethodList def list_length(single_method_list): # This is how I have done it and it works. single_method_list = MyClass([i for i in range(0, 234589)]) for x in (10**p for p in range(1, 8)): if single_method_list.get(x): print("More than", x) first = x else: print("Less than", x) last = x break answer = False while not answer: result = (first + last)/2 result = int(round(result)) print(result) if single_method_list.get(result): first = result print('first', result) else: last = result print('last', result) if single_method_list.get(result) and not single_method_list.get(result + 1): answer = True print(result + 1) a_list = SingleMethodList(list(range(0, 234589))) # python3 #a_list = SingleMethodList(range(0, 234589)) #python2 - I don't understand why test case use list comprehension from xrange, instead of simply rangeit looks like you use python3 and test case is using python2. Note - I just adjusted your code, did not correct algorithm or code/style