Python Console Starting ...

3.13.2 (main, Oct 20 2025, 18:07:39) [Clang 21.0.0git (https:/github.com/llvm/llvm-project 2f05451198e2f222ec66cec489

>>> .....................................................................
import random totalObjects = 100 randomObjects = [] # Test object class: class Object(object): pass # Generate a list of random objects for i in range(totalObjects): # Instance of objects: tempObject = Object() # Set the object's random score random.seed() tempObject.score = random.random() # Set the object's random coordinates: tempObject.coordinates = (random.randint(0, 5), random.randint(0, 5)) # Store object into list: randomObjects.append(tempObject) # Get the 3 largest objects sorted by score: totalLargestObjects = 3
>>> 
import heapq
>>> 
heapq.nlargest(3, ((obj.score, obj) for obj in randomObjects))

>>>


Akuiper @2024