anyway/backend/src/utils/take_most_important.py
Remy Moll 3710a476e8
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 1m45s
Build and deploy the backend to staging / Deploy to staging (pull_request) Failing after 13s
don't break when using sets
2024-09-27 10:13:33 +02:00

17 lines
617 B
Python

from structs.landmark import Landmark
def take_most_important(landmarks: list[Landmark], n_important) -> list[Landmark]:
"""
Given a list of landmarks, return the n_important most important landmarks
Parameters:
landmarks: list[Landmark] - list of landmarks
n_important: int - number of most important landmarks to return
Returns:
list[Landmark] - list of the n_important most important landmarks
"""
# Sort landmarks by attractiveness (descending)
sorted_landmarks = sorted(landmarks, key=lambda x: x.attractiveness, reverse=True)
return sorted_landmarks[:n_important]