0
instanceList = []

class Myclass:
    def __init__(self, int, str):
        self.int = int
        self.str = str

instanceList.append(Myclass(10, "hello"))
instanceList.append(Myclass(5, "world"))
instanceList.append(Myclass(20, "string"))

Is there a way that I can find the index of the instance with the lowest 'int' attribute in 'intanceList'?

For example, a function that could do this:

minIndex = minInt(instanceList)
print(instanceList[minIndex].int)

Where the function 'minInt' would return the index of which instance with the lowest 'int' attribute. Therefore, this code should print '5', and the 'minIndex' variable should equal 1

  • 2
    This is answered here: [How to search list of objects for index of minimum](https://stackoverflow.com/questions/54624235/how-to-search-list-of-objects-for-index-of-minimum) – mkrieger1 Jan 12 '22 at 01:06

0 Answers0