Skip to content

list-reverse-copy (FURB187)#

Derived from the refurb linter.

Fix is always available.

This rule is unstable and in preview. The --preview flag is required for use.

What it does#

Checks for list reversals that can be performed in-place in lieu of creating a new list.

Why is this bad?#

When reversing a list, it's more efficient to use the in-place method .reverse() instead of creating a new list, if the original list is no longer needed.


l = [1, 2, 3]
l = reversed(l)

l = [1, 2, 3]
l = list(reversed(l))

l = [1, 2, 3]
l = l[::-1]

Use instead:

l = [1, 2, 3]