Closed Skylion007 closed 8 months ago
The docs specifically say it's the same behavior:
If multiple items are maximal, the function returns the first one encountered. This is consistent with other sort-stability preserving tools such as sorted(iterable, key=keyfunc, reverse=True)[0] and heapq.nlargest(1, iterable, key=keyfunc).
@Skylion007 Thank you for opening this! I'll go ahead and implement this right now since it seems easy enough.
Done! Thanks again for opening this. This sparked an idea for another check I could add tomorrow.
Overview
sorted(a)[0]
should be replaced withmin(a)
. See https://github.com/astral-sh/ruff/issues/10463 for more details if we should put it under a refurb error codeProposal
Convert
sorted(a)[0]
tomin(a)
. Also convertsorted(a, reverse=True)
tomax(a)
assuming they are equivalent with sort stability (need to double check).