Here is a snippet containing a code that reproduces my error. Why does the sum function pass a class instance instead of a number to the subtract method?
class my_class():
def __init__(self):
pass
def __subtract (x,y, n=1):
return (x - y)**n
def num_generator(self, num):
example_list = []
for idx in range(num):
example_list += [idx]
expression = {y: sum(self.__subtract(x, y) for x in example_list) for y in range(min(example_list), max(example_list) + 1)}
no_vals = max(expression.items(), key=operator.itemgetter(1))[0]
return no_vals
chosen_no = 20
class_instance = my_class()
class_instance.num_generator(chosen_no)
ERROR:
TypeError: unsupported operand type(s) for -: 'my_class' and 'int'
I have been staring at this for 20 minutes now and to me it makes no sense.