Skip to content

Rule Suggestion min/max instead of sorted(l)[0] #10463

@Skylion007

Description

@Skylion007

Saw this in code:

a = sorted(l)[0]
a = sorted(l, reverse=True)[-1] # not sure about this one....

should be

a = min(l)

Additionally, the following code pattern can also be simplified

a = sorted(l, reverse=True)[0] 
a = sorted(l)[-1] # not sure about this, sort stability could make it output a different value, right?

should be

a = max(l)

Is there already a pylint rule for this? I wouldn't be surprised. If not, let's add it as a RUFF rule.

I am not sure about the [-1] variants, as there may be some subtlety there with sort stability?

Metadata

Metadata

Labels

ruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions