Skip to content

Enable ruff RUF002 rule #11377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backtracking/sudoku.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Given a partially filled 9×9 2D array, the objective is to fill a 9×9
Given a partially filled 9x9 2D array, the objective is to fill a 9x9
square grid with digits numbered 1 to 9, so that every row, column, and
and each of the nine 3×3 sub-grids contains all of the digits.
and each of the nine 3x3 sub-grids contains all of the digits.

This can be solved using Backtracking and is similar to n-queens.
We check to see if a cell is safe or not and recursively call the
Expand Down
14 changes: 7 additions & 7 deletions bit_manipulation/single_bit_manipulation_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def set_bit(number: int, position: int) -> int:
Set the bit at position to 1.

Details: perform bitwise or for given number and X.
Where X is a number with all the bits zeroes and bit on given
position one.
Where X is a number with all the bits - zeroes and bit on given
position - one.

>>> set_bit(0b1101, 1) # 0b1111
15
Expand All @@ -26,8 +26,8 @@ def clear_bit(number: int, position: int) -> int:
Set the bit at position to 0.

Details: perform bitwise and for given number and X.
Where X is a number with all the bits ones and bit on given
position zero.
Where X is a number with all the bits - ones and bit on given
position - zero.

>>> clear_bit(0b10010, 1) # 0b10000
16
Expand All @@ -42,8 +42,8 @@ def flip_bit(number: int, position: int) -> int:
Flip the bit at position.

Details: perform bitwise xor for given number and X.
Where X is a number with all the bits zeroes and bit on given
position one.
Where X is a number with all the bits - zeroes and bit on given
position - one.

>>> flip_bit(0b101, 1) # 0b111
7
Expand Down Expand Up @@ -79,7 +79,7 @@ def get_bit(number: int, position: int) -> int:
Get the bit at the given position

Details: perform bitwise and for the given number and X,
Where X is a number with all the bits zeroes and bit on given position one.
Where X is a number with all the bits - zeroes and bit on given position - one.
If the result is not equal to 0, then the bit on the given position is 1, else 0.

>>> get_bit(0b1010, 0)
Expand Down
2 changes: 1 addition & 1 deletion compression/burrows_wheeler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
https://en.wikipedia.org/wiki/Burrows%E2%80%93Wheeler_transform

The BurrowsWheeler transform (BWT, also called block-sorting compression)
The Burrows-Wheeler transform (BWT, also called block-sorting compression)
rearranges a character string into runs of similar characters. This is useful
for compression, since it tends to be easy to compress a string that has runs
of repeated characters by techniques such as move-to-front transform and
Expand Down
4 changes: 2 additions & 2 deletions compression/lempel_ziv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
One of the several implementations of LempelZivWelch compression algorithm
One of the several implementations of Lempel-Ziv-Welch compression algorithm
https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch
"""

Expand Down Expand Up @@ -43,7 +43,7 @@ def add_key_to_lexicon(

def compress_data(data_bits: str) -> str:
"""
Compresses given data_bits using LempelZivWelch compression algorithm
Compresses given data_bits using Lempel-Ziv-Welch compression algorithm
and returns the result as a string
"""
lexicon = {"0": "0", "1": "1"}
Expand Down
4 changes: 2 additions & 2 deletions compression/lempel_ziv_decompress.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
One of the several implementations of LempelZivWelch decompression algorithm
One of the several implementations of Lempel-Ziv-Welch decompression algorithm
https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch
"""

Expand All @@ -26,7 +26,7 @@ def read_file_binary(file_path: str) -> str:

def decompress_data(data_bits: str) -> str:
"""
Decompresses given data_bits using LempelZivWelch compression algorithm
Decompresses given data_bits using Lempel-Ziv-Welch compression algorithm
and returns the result as a string
"""
lexicon = {"0": "0", "1": "1"}
Expand Down
2 changes: 1 addition & 1 deletion data_structures/binary_tree/red_black_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RedBlackTree:
and slower for reading in the average case, though, because they're
both balanced binary search trees, both will get the same asymptotic
performance.
To read more about them, https://en.wikipedia.org/wiki/Redblack_tree
To read more about them, https://en.wikipedia.org/wiki/Red-black_tree
Unless otherwise specified, all asymptotic runtimes are specified in
terms of the size of the tree.
"""
Expand Down
4 changes: 2 additions & 2 deletions digital_image_processing/edge_detection/canny.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def detect_high_low_threshold(
image_shape, destination, threshold_low, threshold_high, weak, strong
):
"""
High-Low threshold detection. If an edge pixels gradient value is higher
High-Low threshold detection. If an edge pixel's gradient value is higher
than the high threshold value, it is marked as a strong edge pixel. If an
edge pixels gradient value is smaller than the high threshold value and
edge pixel's gradient value is smaller than the high threshold value and
larger than the low threshold value, it is marked as a weak edge pixel. If
an edge pixel's value is smaller than the low threshold value, it will be
suppressed.
Expand Down
2 changes: 1 addition & 1 deletion digital_image_processing/index_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def arv12(self):
Atmospherically Resistant Vegetation Index 2
https://www.indexdatabase.de/db/i-single.php?id=396
:return: index
0.18+1.17*(self.nirself.red)/(self.nir+self.red)
-0.18+1.17*(self.nir-self.red)/(self.nir+self.red)
"""
return -0.18 + (1.17 * ((self.nir - self.red) / (self.nir + self.red)))

Expand Down
2 changes: 1 addition & 1 deletion dynamic_programming/combination_sum_iv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
The basic idea is to go over recursively to find the way such that the sum
of chosen elements is “tar”. For every element, we have two choices
1. Include the element in our set of chosen elements.
2. Dont include the element in our set of chosen elements.
2. Don't include the element in our set of chosen elements.
"""


Expand Down
4 changes: 2 additions & 2 deletions electronics/coulombs_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def couloumbs_law(

Reference
----------
Coulomb (1785) "Premier mémoire sur lélectricité et le magnétisme,"
Histoire de lAcadémie Royale des Sciences, pp. 569577.
Coulomb (1785) "Premier mémoire sur l'électricité et le magnétisme,"
Histoire de l'Académie Royale des Sciences, pp. 569-577.

Parameters
----------
Expand Down
6 changes: 3 additions & 3 deletions fuzzy_logic/fuzzy_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class FuzzySet:

# Union Operations
>>> siya.union(sheru)
FuzzySet(name='Siya Sheru', left_boundary=0.4, peak=0.7, right_boundary=1.0)
FuzzySet(name='Siya U Sheru', left_boundary=0.4, peak=0.7, right_boundary=1.0)
"""

name: str
Expand Down Expand Up @@ -147,10 +147,10 @@ def union(self, other) -> FuzzySet:
FuzzySet: A new fuzzy set representing the union.

>>> FuzzySet("a", 0.1, 0.2, 0.3).union(FuzzySet("b", 0.4, 0.5, 0.6))
FuzzySet(name='a b', left_boundary=0.1, peak=0.6, right_boundary=0.35)
FuzzySet(name='a U b', left_boundary=0.1, peak=0.6, right_boundary=0.35)
"""
return FuzzySet(
f"{self.name} {other.name}",
f"{self.name} U {other.name}",
min(self.left_boundary, other.left_boundary),
max(self.right_boundary, other.right_boundary),
(self.peak + other.peak) / 2,
Expand Down
2 changes: 1 addition & 1 deletion hashes/fletcher16.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
The Fletcher checksum is an algorithm for computing a position-dependent
checksum devised by John G. Fletcher (19342012) at Lawrence Livermore Labs
checksum devised by John G. Fletcher (1934-2012) at Lawrence Livermore Labs
in the late 1970s.[1] The objective of the Fletcher checksum was to
provide error-detection properties approaching those of a cyclic
redundancy check but with the lower computational effort associated
Expand Down
2 changes: 1 addition & 1 deletion linear_algebra/lu_decomposition.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Lowerupper (LU) decomposition factors a matrix as a product of a lower
Lower-upper (LU) decomposition factors a matrix as a product of a lower
triangular matrix and an upper triangular matrix. A square matrix has an LU
decomposition under the following conditions:
- If the matrix is invertible, then it has an LU decomposition if and only
Expand Down
2 changes: 1 addition & 1 deletion linear_algebra/src/schur_complement.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def schur_complement(
the pseudo_inv argument.

Link to Wiki: https://en.wikipedia.org/wiki/Schur_complement
See also Convex Optimization Boyd and Vandenberghe, A.5.5
See also Convex Optimization - Boyd and Vandenberghe, A.5.5
>>> import numpy as np
>>> a = np.array([[1, 2], [2, 1]])
>>> b = np.array([[0, 3], [3, 0]])
Expand Down
4 changes: 2 additions & 2 deletions machine_learning/polynomial_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

β = (XᵀX)⁻¹Xᵀy = X⁺y

where X is the design matrix, y is the response vector, and X⁺ denotes the MoorePenrose
where X is the design matrix, y is the response vector, and X⁺ denotes the Moore-Penrose
pseudoinverse of X. In the case of polynomial regression, the design matrix is

|1 x₁ x₁² ⋯ x₁ᵐ|
Expand Down Expand Up @@ -106,7 +106,7 @@ def fit(self, x_train: np.ndarray, y_train: np.ndarray) -> None:

β = (XᵀX)⁻¹Xᵀy = X⁺y

where X⁺ denotes the MoorePenrose pseudoinverse of the design matrix X. This
where X⁺ denotes the Moore-Penrose pseudoinverse of the design matrix X. This
function computes X⁺ using singular value decomposition (SVD).

References:
Expand Down
2 changes: 1 addition & 1 deletion maths/chudnovsky_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def pi(precision: int) -> str:
"""
The Chudnovsky algorithm is a fast method for calculating the digits of PI,
based on Ramanujans PI formulae.
based on Ramanujan's PI formulae.

https://en.wikipedia.org/wiki/Chudnovsky_algorithm

Expand Down
4 changes: 2 additions & 2 deletions maths/entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def calculate_prob(text: str) -> None:
:return: Prints
1) Entropy of information based on 1 alphabet
2) Entropy of information based on couples of 2 alphabet
3) print Entropy of H(X n∣Xn−1)
3) print Entropy of H(X n|Xn-1)

Text from random books. Also, random quotes.
>>> text = ("Behind Winstons back the voice "
>>> text = ("Behind Winston's back the voice "
... "from the telescreen was still "
... "babbling and the overfulfilment")
>>> calculate_prob(text)
Expand Down
4 changes: 2 additions & 2 deletions maths/lucas_lehmer_primality_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
In mathematics, the LucasLehmer test (LLT) is a primality test for Mersenne
In mathematics, the Lucas-Lehmer test (LLT) is a primality test for Mersenne
numbers. https://en.wikipedia.org/wiki/Lucas%E2%80%93Lehmer_primality_test

A Mersenne number is a number that is one less than a power of two.
That is M_p = 2^p - 1
https://en.wikipedia.org/wiki/Mersenne_prime

The LucasLehmer test is the primality test used by the
The Lucas-Lehmer test is the primality test used by the
Great Internet Mersenne Prime Search (GIMPS) to locate large primes.
"""

Expand Down
2 changes: 1 addition & 1 deletion maths/modular_division.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def modular_division(a: int, b: int, n: int) -> int:
GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor )

Given three integers a, b, and n, such that gcd(a,n)=1 and n>1, the algorithm should
return an integer x such that 0≤x≤n1, and b/a=x(modn) (that is, b=ax(modn)).
return an integer x such that 0≤x≤n-1, and b/a=x(modn) (that is, b=ax(modn)).

Theorem:
a has a multiplicative inverse modulo n iff gcd(a,n) = 1
Expand Down
2 changes: 1 addition & 1 deletion maths/numerical_analysis/bisection_2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Given a function on floating number f(x) and two floating numbers ‘a’ and ‘b’ such that
Given a function on floating number f(x) and two floating numbers `a` and `b` such that
f(a) * f(b) < 0 and f(x) is continuous in [a, b].
Here f(x) represents algebraic or transcendental equation.
Find root of function in interval [a, b] (Or find a value of x such that f(x) is 0)
Expand Down
2 changes: 1 addition & 1 deletion maths/numerical_analysis/nevilles_method.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Python program to show how to interpolate and evaluate a polynomial
using Neville's method.
Nevilles method evaluates a polynomial that passes through a
Neville's method evaluates a polynomial that passes through a
given set of x and y points for a particular x value (x0) using the
Newton polynomial form.
Reference:
Expand Down
6 changes: 3 additions & 3 deletions maths/simultaneous_linear_equation_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
https://en.wikipedia.org/wiki/Augmented_matrix

This algorithm solves simultaneous linear equations of the form
λa + λb + λc + λd + ... = γ as [λ, λ, λ, λ, ..., γ]
Where λ & γ are individual coefficients, the no. of equations = no. of coefficients - 1
λa + λb + λc + λd + ... = y as [λ, λ, λ, λ, ..., y]
Where λ & y are individual coefficients, the no. of equations = no. of coefficients - 1

Note in order to work there must exist 1 equation where all instances of λ and γ != 0
Note in order to work there must exist 1 equation where all instances of λ and y != 0
"""


Expand Down
4 changes: 2 additions & 2 deletions matrix/largest_square_area_in_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@

Approach:
We initialize another matrix (dp) with the same dimensions
as the original one initialized with all 0s.
as the original one initialized with all 0's.

dp_array(i,j) represents the side length of the maximum square whose
bottom right corner is the cell with index (i,j) in the original matrix.

Starting from index (0,0), for every 1 found in the original matrix,
we update the value of the current element as

dp_array(i,j)=dp_array(dp(i1,j),dp_array(i1,j1),dp_array(i,j1)) + 1.
dp_array(i,j)=dp_array(dp(i-1,j),dp_array(i-1,j-1),dp_array(i,j-1)) + 1.
"""


Expand Down
2 changes: 1 addition & 1 deletion matrix/spiral_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def spiral_traversal(matrix: list[list]) -> list[int]:
Algorithm:
Step 1. first pop the 0 index list. (which is [1,2,3,4] and concatenate the
output of [step 2])
Step 2. Now perform matrixs Transpose operation (Change rows to column
Step 2. Now perform matrix's Transpose operation (Change rows to column
and vice versa) and reverse the resultant matrix.
Step 3. Pass the output of [2nd step], to same recursive function till
base case hits.
Expand Down
4 changes: 2 additions & 2 deletions neural_network/back_propagation_neural_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

"""

A Framework of Back Propagation Neural Network(BP) model
A Framework of Back Propagation Neural Network (BP) model

Easy to use:
* add many layers as you want !!!
* add many layers as you want ! ! !
* clearly see how the loss decreasing
Easy to expand:
* more activation functions
Expand Down
2 changes: 1 addition & 1 deletion other/davis_putnam_logemann_loveland.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

"""
DavisPutnamLogemannLoveland (DPLL) algorithm is a complete, backtracking-based
Davis-Putnam-Logemann-Loveland (DPLL) algorithm is a complete, backtracking-based
search algorithm for deciding the satisfiability of propositional logic formulae in
conjunctive normal form, i.e, for solving the Conjunctive Normal Form SATisfiability
(CNF-SAT) problem.
Expand Down
2 changes: 1 addition & 1 deletion other/fischer_yates_shuffle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python
"""
The FisherYates shuffle is an algorithm for generating a random permutation of a
The Fisher-Yates shuffle is an algorithm for generating a random permutation of a
finite sequence.
For more details visit
wikipedia/Fischer-Yates-Shuffle.
Expand Down
2 changes: 1 addition & 1 deletion physics/archimedes_principle_of_buoyant_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
fluid. This principle was discovered by the Greek mathematician Archimedes.

Equation for calculating buoyant force:
Fb = ρ * V * g
Fb = p * V * g

https://en.wikipedia.org/wiki/Archimedes%27_principle
"""
Expand Down
8 changes: 4 additions & 4 deletions physics/center_of_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
is the particle equivalent of a given object for the application of Newton's laws of
motion.

In the case of a system of particles P_i, i = 1,..., n , each with mass m_i that are
located in space with coordinates r_i, i = 1,..., n , the coordinates R of the center
In the case of a system of particles P_i, i = 1, ..., n , each with mass m_i that are
located in space with coordinates r_i, i = 1, ..., n , the coordinates R of the center
of mass corresponds to:

R = (Σ(mi * ri) / Σ(mi))
Expand All @@ -36,8 +36,8 @@ def center_of_mass(particles: list[Particle]) -> Coord3D:
Input Parameters
----------------
particles: list(Particle):
A list of particles where each particle is a tuple with it´s (x, y, z) position and
it´s mass.
A list of particles where each particle is a tuple with it's (x, y, z) position and
it's mass.

Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion physics/centripetal_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The unit of centripetal force is newton.

The centripetal force is always directed perpendicular to the
direction of the objects displacement. Using Newtons second
direction of the object's displacement. Using Newton's second
law of motion, it is found that the centripetal force of an object
moving in a circular path always acts towards the centre of the circle.
The Centripetal Force Formula is given as the product of mass (in kg)
Expand Down
Loading