This rule raises an issue when an iterable is reversed using slicing, like [::-1], before being passed to set(),
sorted(), or reversed().
Reversing an iterable using slicing, likle [::-1], before passing it to set(), sorted(), or
reversed() is unnecessary and inefficient. The slicing operation creates a new copy of the iterable in reverse order, which is not needed
for the following reasons:
set(): The order of elements in a set is inherently undefined, so reversing the iterable before creating the set has no effect on
the final set, and it introduces unnecessary computation. sorted(): The sorted() function has a reverse parameter that provides a more efficient way to sort in
descending order. Using slicing to reverse the result of sorted() is less efficient and less readable. reversed(): Applying reversed() twice on the same iterable effectively returns the original iterable, if it supports
direct iteration. If the iterable is a one-time iterator, then you will need to create an iterator from the original iterable using
iter(iterable). Using slicing adds unnecessary overhead. To fix these issues remove the redundant slicing operation: * set(iterable[::-1]): Replace with set(iterable). *
sorted(iterable)[::-1]: Replace with sorted(iterable, reverse=True). * reversed(iterable[::-1]): Replace with
iterable if it supports direct iteration, or iter(iterable) if it is a one-time iterator.
iterable = [1, 3, 2] result = set(iterable[::-1]) # Noncompliant
iterable = [1, 3, 2] result = set(iterable)