1

What does min() function in python return when it finds 2 minimum objects having the same attribute?

For Example - I have a class named name Node as follows-

class Node:
    def __init__(self, f):
        self.f = f

I want to find the object having the minimum 'f' in a list of objects.

My code for doing this is as follows.

def myFunction():
    Node1 = Node(1)
    Node2 = Node(2)
    Node3 = Node(1)
    list = [Node1, Node2, Node3]
    minimum = min(list, key=attrgetter("f"))

Which object will the function return, Node1 or Node3?

Ishaan Shah
  • 49
  • 1
  • 5

0 Answers0