mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-28 07:21:07 +00:00
Enable ruff RUF007 rule
This commit is contained in:
parent
f5ed227553
commit
ce75a04021
|
@ -5,6 +5,7 @@ https://epaperpress.com/sortsearch/download/skiplist.pdf
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from itertools import pairwise
|
||||
from random import random
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
|
@ -389,7 +390,7 @@ def test_delete_doesnt_leave_dead_nodes():
|
|||
|
||||
def test_iter_always_yields_sorted_values():
|
||||
def is_sorted(lst):
|
||||
return all(next_item >= item for item, next_item in zip(lst, lst[1:]))
|
||||
return all(next_item >= item for item, next_item in pairwise(lst))
|
||||
|
||||
skip_list = SkipList()
|
||||
for i in range(10):
|
||||
|
|
|
@ -16,7 +16,6 @@ lint.ignore = [ # `ruff rule S101` for a description of that rule
|
|||
"RUF001", # String contains ambiguous {}. Did you mean {}?
|
||||
"RUF002", # Docstring contains ambiguous {}. Did you mean {}?
|
||||
"RUF003", # Comment contains ambiguous {}. Did you mean {}?
|
||||
"RUF007", # Prefer itertools.pairwise() over zip() when iterating over successive pairs
|
||||
"S101", # Use of `assert` detected -- DO NOT FIX
|
||||
"S113", # Probable use of requests call without timeout -- FIX ME
|
||||
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes -- FIX ME
|
||||
|
|
|
@ -3,6 +3,8 @@ Bead sort only works for sequences of non-negative integers.
|
|||
https://en.wikipedia.org/wiki/Bead_sort
|
||||
"""
|
||||
|
||||
from itertools import pairwise
|
||||
|
||||
|
||||
def bead_sort(sequence: list) -> list:
|
||||
"""
|
||||
|
@ -31,7 +33,7 @@ def bead_sort(sequence: list) -> list:
|
|||
if any(not isinstance(x, int) or x < 0 for x in sequence):
|
||||
raise TypeError("Sequence must be list of non-negative integers")
|
||||
for _ in range(len(sequence)):
|
||||
for i, (rod_upper, rod_lower) in enumerate(zip(sequence, sequence[1:])):
|
||||
for i, (rod_upper, rod_lower) in enumerate(pairwise(sequence)):
|
||||
if rod_upper > rod_lower:
|
||||
sequence[i] -= rod_upper - rod_lower
|
||||
sequence[i + 1] += rod_upper - rod_lower
|
||||
|
|
Loading…
Reference in New Issue
Block a user