TypeError: ‘

Solution for TypeError: ‘<' not supported between instances is Given Below:

I’m trying to create a code to solve the backpack problem using the greedy algorithm problem. When I run the code I get TypeError: '<' not supported between instances of 'BagObject' and 'BagObject'

TypeError                                 Traceback (most recent call last)
<ipython-input-62-a93714b54a16> in <module>()
     29 values = [10,50,20,30,60]
     30 capacity = 11
---> 31 maxValue = getMaxValue(weight, values, capacity)
     32 print("Max value in the backpack =", maxValue)

<ipython-input-62-a93714b54a16> in getMaxValue(weight, values, capacity)
     14             arraySort.append (BagObject (weight [i], values [i], i))
     15 
---> 16         arraySort.sort(reverse = True)
     17 
     18         counterValue = 0

TypeError: '<' not supported between instances of 'BagObject' and 'BagObject

This is the code:

    class BagObject:
        def __init__(self, weight, value, index):
            self.index = index
            self.weight = weight
            self.value = value
            self.report = value // weight
            def __lt__(self, other):
              return self.report & lt; other.report
          
    def getMaxValue (weight, values, capacity):
            arraySort = []
            for i in range (len(weight)):
                arraySort.append(BagObject(weight[i], values[i], I))

            arraySort.sort(reverse=True)

            counterValue = 0
            print(counterValue)
            for object in arraySort:
                currentWeight = int(object.weight)
                currentValue = int(object.value)
                if capacity - currentWeight >= 0:
                    capacity -= currentWeight
                    counterValue += currentValue
            return counterValue
  
    weight = [1, 5, 3, 2, 4]
    values = [10, 50, 20, 30, 60]
    capacity = 11
    maxValue = getMaxValue(weight, values, capacity)
    print("Max value in the backpack =", maxValue)