anyway/backend/src/utils/take_most_important.py
Remy Moll cdc9b0ecd1
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m4s
Build and deploy the backend to staging / Deploy to staging (pull_request) Failing after 18s
ensure attractiveness is always an int
2024-09-27 09:47:10 +02:00

17 lines
588 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)
landmarks.sort(key=lambda x: x.attractiveness, reverse=True)
return landmarks[:n_important]