mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
Flake8: Drop ignore of issue A003 (#7949)
* Flake8: Drop ignore of issue A003 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
598f6a26a1
commit
45b3383c39
4
.flake8
4
.flake8
|
@ -1,8 +1,8 @@
|
|||
[flake8]
|
||||
max-line-length = 88
|
||||
max-complexity = 25
|
||||
# max-complexity should be 10
|
||||
max-complexity = 23
|
||||
extend-ignore =
|
||||
A003 # Class attribute is shadowing a python builtin
|
||||
# Formatting style for `black`
|
||||
E203 # Whitespace before ':'
|
||||
W503 # Line break occurred before a binary operator
|
||||
|
|
10
DIRECTORY.md
10
DIRECTORY.md
|
@ -48,6 +48,7 @@
|
|||
* [Highest Set Bit](bit_manipulation/highest_set_bit.py)
|
||||
* [Index Of Rightmost Set Bit](bit_manipulation/index_of_rightmost_set_bit.py)
|
||||
* [Is Even](bit_manipulation/is_even.py)
|
||||
* [Is Power Of Two](bit_manipulation/is_power_of_two.py)
|
||||
* [Reverse Bits](bit_manipulation/reverse_bits.py)
|
||||
* [Single Bit Manipulation Operations](bit_manipulation/single_bit_manipulation_operations.py)
|
||||
|
||||
|
@ -315,6 +316,7 @@
|
|||
* [Minimum Partition](dynamic_programming/minimum_partition.py)
|
||||
* [Minimum Squares To Represent A Number](dynamic_programming/minimum_squares_to_represent_a_number.py)
|
||||
* [Minimum Steps To One](dynamic_programming/minimum_steps_to_one.py)
|
||||
* [Minimum Tickets Cost](dynamic_programming/minimum_tickets_cost.py)
|
||||
* [Optimal Binary Search Tree](dynamic_programming/optimal_binary_search_tree.py)
|
||||
* [Palindrome Partitioning](dynamic_programming/palindrome_partitioning.py)
|
||||
* [Rod Cutting](dynamic_programming/rod_cutting.py)
|
||||
|
@ -496,8 +498,6 @@
|
|||
## Maths
|
||||
* [3N Plus 1](maths/3n_plus_1.py)
|
||||
* [Abs](maths/abs.py)
|
||||
* [Abs Max](maths/abs_max.py)
|
||||
* [Abs Min](maths/abs_min.py)
|
||||
* [Add](maths/add.py)
|
||||
* [Addition Without Arithmetic](maths/addition_without_arithmetic.py)
|
||||
* [Aliquot Sum](maths/aliquot_sum.py)
|
||||
|
@ -653,6 +653,7 @@
|
|||
* [Matrix Operation](matrix/matrix_operation.py)
|
||||
* [Max Area Of Island](matrix/max_area_of_island.py)
|
||||
* [Nth Fibonacci Using Matrix Exponentiation](matrix/nth_fibonacci_using_matrix_exponentiation.py)
|
||||
* [Pascal Triangle](matrix/pascal_triangle.py)
|
||||
* [Rotate Matrix](matrix/rotate_matrix.py)
|
||||
* [Searching In Sorted Matrix](matrix/searching_in_sorted_matrix.py)
|
||||
* [Sherman Morrison](matrix/sherman_morrison.py)
|
||||
|
@ -674,7 +675,6 @@
|
|||
## Other
|
||||
* [Activity Selection](other/activity_selection.py)
|
||||
* [Alternative List Arrange](other/alternative_list_arrange.py)
|
||||
* [Check Strong Password](other/check_strong_password.py)
|
||||
* [Davisb Putnamb Logemannb Loveland](other/davisb_putnamb_logemannb_loveland.py)
|
||||
* [Dijkstra Bankers Algorithm](other/dijkstra_bankers_algorithm.py)
|
||||
* [Doomsday](other/doomsday.py)
|
||||
|
@ -689,8 +689,7 @@
|
|||
* [Magicdiamondpattern](other/magicdiamondpattern.py)
|
||||
* [Maximum Subarray](other/maximum_subarray.py)
|
||||
* [Nested Brackets](other/nested_brackets.py)
|
||||
* [Pascal Triangle](other/pascal_triangle.py)
|
||||
* [Password Generator](other/password_generator.py)
|
||||
* [Password](other/password.py)
|
||||
* [Quine](other/quine.py)
|
||||
* [Scoring Algorithm](other/scoring_algorithm.py)
|
||||
* [Sdes](other/sdes.py)
|
||||
|
@ -701,6 +700,7 @@
|
|||
* [Casimir Effect](physics/casimir_effect.py)
|
||||
* [Centripetal Force](physics/centripetal_force.py)
|
||||
* [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py)
|
||||
* [Hubble Parameter](physics/hubble_parameter.py)
|
||||
* [Ideal Gas Law](physics/ideal_gas_law.py)
|
||||
* [Kinetic Energy](physics/kinetic_energy.py)
|
||||
* [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py)
|
||||
|
|
|
@ -46,7 +46,7 @@ class FenwickTree:
|
|||
self.size = len(arr)
|
||||
self.tree = deepcopy(arr)
|
||||
for i in range(1, self.size):
|
||||
j = self.next(i)
|
||||
j = self.next_(i)
|
||||
if j < self.size:
|
||||
self.tree[j] += self.tree[i]
|
||||
|
||||
|
@ -64,13 +64,13 @@ class FenwickTree:
|
|||
"""
|
||||
arr = self.tree[:]
|
||||
for i in range(self.size - 1, 0, -1):
|
||||
j = self.next(i)
|
||||
j = self.next_(i)
|
||||
if j < self.size:
|
||||
arr[j] -= arr[i]
|
||||
return arr
|
||||
|
||||
@staticmethod
|
||||
def next(index: int) -> int:
|
||||
def next_(index: int) -> int:
|
||||
return index + (index & (-index))
|
||||
|
||||
@staticmethod
|
||||
|
@ -102,7 +102,7 @@ class FenwickTree:
|
|||
return
|
||||
while index < self.size:
|
||||
self.tree[index] += value
|
||||
index = self.next(index)
|
||||
index = self.next_(index)
|
||||
|
||||
def update(self, index: int, value: int) -> None:
|
||||
"""
|
||||
|
|
|
@ -88,13 +88,6 @@ class Heap:
|
|||
for i in range(self.heap_size // 2 - 1, -1, -1):
|
||||
self.max_heapify(i)
|
||||
|
||||
def max(self) -> float:
|
||||
"""return the max in the heap"""
|
||||
if self.heap_size >= 1:
|
||||
return self.h[0]
|
||||
else:
|
||||
raise Exception("Empty heap")
|
||||
|
||||
def extract_max(self) -> float:
|
||||
"""get and remove max from heap"""
|
||||
if self.heap_size >= 2:
|
||||
|
|
|
@ -13,7 +13,7 @@ test_data_even = (4, 6, 2, 0, 8, 10, 3, -2)
|
|||
@dataclass
|
||||
class Node:
|
||||
data: int
|
||||
next: Node | None
|
||||
next_node: Node | None
|
||||
|
||||
|
||||
class SortedLinkedList:
|
||||
|
@ -32,7 +32,7 @@ class SortedLinkedList:
|
|||
node = self.head
|
||||
while node:
|
||||
yield node.data
|
||||
node = node.next
|
||||
node = node.next_node
|
||||
|
||||
def __len__(self) -> int:
|
||||
"""
|
||||
|
|
|
@ -42,8 +42,8 @@ class Deque:
|
|||
"""
|
||||
|
||||
val: Any = None
|
||||
next: Deque._Node | None = None
|
||||
prev: Deque._Node | None = None
|
||||
next_node: Deque._Node | None = None
|
||||
prev_node: Deque._Node | None = None
|
||||
|
||||
class _Iterator:
|
||||
"""
|
||||
|
@ -81,7 +81,7 @@ class Deque:
|
|||
# finished iterating
|
||||
raise StopIteration
|
||||
val = self._cur.val
|
||||
self._cur = self._cur.next
|
||||
self._cur = self._cur.next_node
|
||||
|
||||
return val
|
||||
|
||||
|
@ -128,8 +128,8 @@ class Deque:
|
|||
self._len = 1
|
||||
else:
|
||||
# connect nodes
|
||||
self._back.next = node
|
||||
node.prev = self._back
|
||||
self._back.next_node = node
|
||||
node.prev_node = self._back
|
||||
self._back = node # assign new back to the new node
|
||||
|
||||
self._len += 1
|
||||
|
@ -170,8 +170,8 @@ class Deque:
|
|||
self._len = 1
|
||||
else:
|
||||
# connect nodes
|
||||
node.next = self._front
|
||||
self._front.prev = node
|
||||
node.next_node = self._front
|
||||
self._front.prev_node = node
|
||||
self._front = node # assign new front to the new node
|
||||
|
||||
self._len += 1
|
||||
|
@ -264,10 +264,9 @@ class Deque:
|
|||
assert not self.is_empty(), "Deque is empty."
|
||||
|
||||
topop = self._back
|
||||
self._back = self._back.prev # set new back
|
||||
self._back.next = (
|
||||
None # drop the last node - python will deallocate memory automatically
|
||||
)
|
||||
self._back = self._back.prev_node # set new back
|
||||
# drop the last node - python will deallocate memory automatically
|
||||
self._back.next_node = None
|
||||
|
||||
self._len -= 1
|
||||
|
||||
|
@ -300,8 +299,8 @@ class Deque:
|
|||
assert not self.is_empty(), "Deque is empty."
|
||||
|
||||
topop = self._front
|
||||
self._front = self._front.next # set new front and drop the first node
|
||||
self._front.prev = None
|
||||
self._front = self._front.next_node # set new front and drop the first node
|
||||
self._front.prev_node = None
|
||||
|
||||
self._len -= 1
|
||||
|
||||
|
@ -385,8 +384,8 @@ class Deque:
|
|||
# compare every value
|
||||
if me.val != oth.val:
|
||||
return False
|
||||
me = me.next
|
||||
oth = oth.next
|
||||
me = me.next_node
|
||||
oth = oth.next_node
|
||||
|
||||
return True
|
||||
|
||||
|
@ -424,7 +423,7 @@ class Deque:
|
|||
while aux is not None:
|
||||
# append the values in a list to display
|
||||
values_list.append(aux.val)
|
||||
aux = aux.next
|
||||
aux = aux.next_node
|
||||
|
||||
return "[" + ", ".join(repr(val) for val in values_list) + "]"
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ class Vector:
|
|||
__sub__(other: Vector): vector subtraction
|
||||
__mul__(other: float): scalar multiplication
|
||||
__mul__(other: Vector): dot product
|
||||
set(components: Collection[float]): changes the vector components
|
||||
copy(): copies this vector and returns it
|
||||
component(i): gets the i-th component (0-indexed)
|
||||
change_component(pos: int, value: float): changes specified component
|
||||
|
@ -119,17 +118,6 @@ class Vector:
|
|||
else: # error case
|
||||
raise Exception("invalid operand!")
|
||||
|
||||
def set(self, components: Collection[float]) -> None:
|
||||
"""
|
||||
input: new components
|
||||
changes the components of the vector.
|
||||
replaces the components with newer one.
|
||||
"""
|
||||
if len(components) > 0:
|
||||
self.__components = list(components)
|
||||
else:
|
||||
raise Exception("please give any vector")
|
||||
|
||||
def copy(self) -> Vector:
|
||||
"""
|
||||
copies this vector and returns it.
|
||||
|
|
|
@ -166,14 +166,14 @@ class LFUCache(Generic[T, U]):
|
|||
or as a function decorator.
|
||||
|
||||
>>> cache = LFUCache(2)
|
||||
>>> cache.set(1, 1)
|
||||
>>> cache.set(2, 2)
|
||||
>>> cache.put(1, 1)
|
||||
>>> cache.put(2, 2)
|
||||
>>> cache.get(1)
|
||||
1
|
||||
>>> cache.set(3, 3)
|
||||
>>> cache.put(3, 3)
|
||||
>>> cache.get(2) is None
|
||||
True
|
||||
>>> cache.set(4, 4)
|
||||
>>> cache.put(4, 4)
|
||||
>>> cache.get(1) is None
|
||||
True
|
||||
>>> cache.get(3)
|
||||
|
@ -224,7 +224,7 @@ class LFUCache(Generic[T, U]):
|
|||
>>> 1 in cache
|
||||
False
|
||||
|
||||
>>> cache.set(1, 1)
|
||||
>>> cache.put(1, 1)
|
||||
>>> 1 in cache
|
||||
True
|
||||
"""
|
||||
|
@ -250,7 +250,7 @@ class LFUCache(Generic[T, U]):
|
|||
self.miss += 1
|
||||
return None
|
||||
|
||||
def set(self, key: T, value: U) -> None:
|
||||
def put(self, key: T, value: U) -> None:
|
||||
"""
|
||||
Sets the value for the input key and updates the Double Linked List
|
||||
"""
|
||||
|
@ -297,7 +297,7 @@ class LFUCache(Generic[T, U]):
|
|||
result = cls.decorator_function_to_instance_map[func].get(args[0])
|
||||
if result is None:
|
||||
result = func(*args)
|
||||
cls.decorator_function_to_instance_map[func].set(args[0], result)
|
||||
cls.decorator_function_to_instance_map[func].put(args[0], result)
|
||||
return result
|
||||
|
||||
def cache_info() -> LFUCache[T, U]:
|
||||
|
|
|
@ -150,8 +150,8 @@ class LRUCache(Generic[T, U]):
|
|||
|
||||
>>> cache = LRUCache(2)
|
||||
|
||||
>>> cache.set(1, 1)
|
||||
>>> cache.set(2, 2)
|
||||
>>> cache.put(1, 1)
|
||||
>>> cache.put(2, 2)
|
||||
>>> cache.get(1)
|
||||
1
|
||||
|
||||
|
@ -166,7 +166,7 @@ class LRUCache(Generic[T, U]):
|
|||
{1: Node: key: 1, val: 1, has next: True, has prev: True, \
|
||||
2: Node: key: 2, val: 2, has next: True, has prev: True}
|
||||
|
||||
>>> cache.set(3, 3)
|
||||
>>> cache.put(3, 3)
|
||||
|
||||
>>> cache.list
|
||||
DoubleLinkedList,
|
||||
|
@ -182,7 +182,7 @@ class LRUCache(Generic[T, U]):
|
|||
>>> cache.get(2) is None
|
||||
True
|
||||
|
||||
>>> cache.set(4, 4)
|
||||
>>> cache.put(4, 4)
|
||||
|
||||
>>> cache.get(1) is None
|
||||
True
|
||||
|
@ -238,7 +238,7 @@ class LRUCache(Generic[T, U]):
|
|||
>>> 1 in cache
|
||||
False
|
||||
|
||||
>>> cache.set(1, 1)
|
||||
>>> cache.put(1, 1)
|
||||
|
||||
>>> 1 in cache
|
||||
True
|
||||
|
@ -266,7 +266,7 @@ class LRUCache(Generic[T, U]):
|
|||
self.miss += 1
|
||||
return None
|
||||
|
||||
def set(self, key: T, value: U) -> None:
|
||||
def put(self, key: T, value: U) -> None:
|
||||
"""
|
||||
Sets the value for the input key and updates the Double Linked List
|
||||
"""
|
||||
|
@ -315,7 +315,7 @@ class LRUCache(Generic[T, U]):
|
|||
result = cls.decorator_function_to_instance_map[func].get(args[0])
|
||||
if result is None:
|
||||
result = func(*args)
|
||||
cls.decorator_function_to_instance_map[func].set(args[0], result)
|
||||
cls.decorator_function_to_instance_map[func].put(args[0], result)
|
||||
return result
|
||||
|
||||
def cache_info() -> LRUCache[T, U]:
|
||||
|
|
Loading…
Reference in New Issue
Block a user