Skip to content

Commit 0a42ae9

Browse files
authored
Fix all errors mentioned in pre-commit run (TheAlgorithms#2512)
* Fix all errors mentioned in pre-commit run: - Fix end of file - Remove trailing whitespace - Fix files with black - Fix imports with isort * Fix errors
1 parent e6e2dc6 commit 0a42ae9

File tree

14 files changed

+88
-87
lines changed

14 files changed

+88
-87
lines changed

.github/stale.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ markComment: >
1616
for your contributions.
1717
# Comment to post when closing a stale issue. Set to `false` to disable
1818
closeComment: >
19-
Please reopen this issue once you commit the changes requested or
19+
Please reopen this issue once you commit the changes requested or
2020
make improvements on the code. Thank you for your contributions.

.github/workflows/autoblack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
black .
2020
isort --profile black .
2121
git config --global user.name github-actions
22-
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
22+
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
2323
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
2424
git commit -am "fixup! Format Python code with psf/black push"
2525
git push --force origin HEAD:$GITHUB_REF

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
include:
1010
- name: Build
1111
before_script:
12-
- black --check . || true
12+
- black --check . || true
1313
- flake8 --ignore=E203,W503 --max-complexity=25 --max-line-length=88 --statistics --count .
1414
- scripts/validate_filenames.py # no uppercase, no spaces, in a directory
1515
- pip install -r requirements.txt # fast fail on black, flake8, validate_filenames

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# The Algorithms - Python
2-
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/TheAlgorithms/Python)
2+
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/TheAlgorithms/Python)
33
[![Gitter chat](https://img.shields.io/badge/Chat-Gitter-ff69b4.svg?label=Chat&logo=gitter&style=flat-square)](https://gitter.im/TheAlgorithms) 
44
[![Build Status](https://img.shields.io/travis/TheAlgorithms/Python.svg?label=Travis%20CI&logo=travis&style=flat-square)](https://travis-ci.com/TheAlgorithms/Python) 
55
[![LGTM](https://img.shields.io/lgtm/alerts/github/TheAlgorithms/Python.svg?label=LGTM&logo=LGTM&style=flat-square)](https://lgtm.com/projects/g/TheAlgorithms/Python/alerts) 

ciphers/prehistoric_men.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Braidwood, Illustrated by Susan T. Richert
33

44

55
This eBook is for the use of anyone anywhere in the United States and most
6-
other parts of the world at no cost and with almost no restrictions
6+
other parts of the world at no cost and with almost no restrictions
77
whatsoever. You may copy it, give it away or re-use it under the terms of
8-
the Project Gutenberg License included with this eBook or online at
8+
the Project Gutenberg License included with this eBook or online at
99
www.gutenberg.org. If you are not located in the United States, you'll have
1010
to check the laws of the country where you are located before using this ebook.
1111

@@ -7109,9 +7109,9 @@ and permanent future for Project Gutenberg-tm and future
71097109
generations. To learn more about the Project Gutenberg Literary
71107110
Archive Foundation and how your efforts and donations can help, see
71117111
Sections 3 and 4 and the Foundation information page at
7112-
www.gutenberg.org
7112+
www.gutenberg.org
71137113

7114-
Section 3. Information about the Project Gutenberg Literary
7114+
Section 3. Information about the Project Gutenberg Literary
71157115
Archive Foundation
71167116

71177117
The Project Gutenberg Literary Archive Foundation is a non profit

computer_vision/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Computer vision is a field of computer science that works on enabling computers to see,
44
identify and process images in the same way that human vision does, and then provide appropriate output.
5-
It is like imparting human intelligence and instincts to a computer.
5+
It is like imparting human intelligence and instincts to a computer.
66
Image processing and computer vision and little different from each other.Image processing means applying some algorithms for transforming image from one form to other like smoothing,contrasting, stretching etc
7-
While in computer vision comes from modelling image processing using the techniques of machine learning.Computer vision applies machine learning to recognize patterns for interpretation of images.
7+
While in computer vision comes from modelling image processing using the techniques of machine learning.Computer vision applies machine learning to recognize patterns for interpretation of images.
88
Much like the process of visual reasoning of human vision

graphics/vector3_for_2d_rendering.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
"""
44

55
from __future__ import annotations
6+
67
import math
78

89
__version__ = "2020.9.26"
910
__author__ = "xcodz-dot, cclaus, dhruvmanila"
1011

1112

12-
def convert_to_2d(x: float, y: float, z: float, scale: float,
13-
distance: float) -> tuple[float, float]:
13+
def convert_to_2d(
14+
x: float, y: float, z: float, scale: float, distance: float
15+
) -> tuple[float, float]:
1416
"""
1517
Converts 3d point to a 2d drawable point
1618
@@ -26,15 +28,17 @@ def convert_to_2d(x: float, y: float, z: float, scale: float,
2628
TypeError: Input values must either be float or int: ['1', 2, 3, 10, 10]
2729
"""
2830
if not all(isinstance(val, (float, int)) for val in locals().values()):
29-
raise TypeError("Input values must either be float or int: "
30-
f"{list(locals().values())}")
31+
raise TypeError(
32+
"Input values must either be float or int: " f"{list(locals().values())}"
33+
)
3134
projected_x = ((x * distance) / (z + distance)) * scale
3235
projected_y = ((y * distance) / (z + distance)) * scale
3336
return projected_x, projected_y
3437

3538

36-
def rotate(x: float, y: float, z: float, axis: str,
37-
angle: float) -> tuple[float, float, float]:
39+
def rotate(
40+
x: float, y: float, z: float, axis: str, angle: float
41+
) -> tuple[float, float, float]:
3842
"""
3943
rotate a point around a certain axis with a certain angle
4044
angle can be any integer between 1, 360 and axis can be any one of
@@ -67,18 +71,20 @@ def rotate(x: float, y: float, z: float, axis: str,
6771
input_variables = locals()
6872
del input_variables["axis"]
6973
if not all(isinstance(val, (float, int)) for val in input_variables.values()):
70-
raise TypeError("Input values except axis must either be float or int: "
71-
f"{list(input_variables.values())}")
74+
raise TypeError(
75+
"Input values except axis must either be float or int: "
76+
f"{list(input_variables.values())}"
77+
)
7278
angle = (angle % 360) / 450 * 180 / math.pi
73-
if axis == 'z':
79+
if axis == "z":
7480
new_x = x * math.cos(angle) - y * math.sin(angle)
7581
new_y = y * math.cos(angle) + x * math.sin(angle)
7682
new_z = z
77-
elif axis == 'x':
83+
elif axis == "x":
7884
new_y = y * math.cos(angle) - z * math.sin(angle)
7985
new_z = z * math.cos(angle) + y * math.sin(angle)
8086
new_x = x
81-
elif axis == 'y':
87+
elif axis == "y":
8288
new_x = x * math.cos(angle) - z * math.sin(angle)
8389
new_z = z * math.cos(angle) + x * math.sin(angle)
8490
new_y = y

linear_algebra/README.md

+46-46
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
1-
# Linear algebra library for Python
1+
# Linear algebra library for Python
22

3-
This module contains classes and functions for doing linear algebra.
3+
This module contains classes and functions for doing linear algebra.
44

55
---
66

7-
## Overview
7+
## Overview
88

9-
### class Vector
9+
### class Vector
1010
-
11-
- This class represents a vector of arbitrary size and related operations.
12-
13-
**Overview about the methods:**
14-
15-
- constructor(components : list) : init the vector
16-
- set(components : list) : changes the vector components.
17-
- \_\_str\_\_() : toString method
18-
- component(i : int): gets the i-th component (start by 0)
19-
- \_\_len\_\_() : gets the size / length of the vector (number of components)
20-
- euclidLength() : returns the eulidean length of the vector.
21-
- operator + : vector addition
22-
- operator - : vector subtraction
23-
- operator * : scalar multiplication and dot product
24-
- copy() : copies this vector and returns it.
25-
- changeComponent(pos,value) : changes the specified component.
26-
27-
- function zeroVector(dimension)
28-
- returns a zero vector of 'dimension'
29-
- function unitBasisVector(dimension,pos)
30-
- returns a unit basis vector with a One at index 'pos' (indexing at 0)
31-
- function axpy(scalar,vector1,vector2)
32-
- computes the axpy operation
11+
- This class represents a vector of arbitrary size and related operations.
12+
13+
**Overview about the methods:**
14+
15+
- constructor(components : list) : init the vector
16+
- set(components : list) : changes the vector components.
17+
- \_\_str\_\_() : toString method
18+
- component(i : int): gets the i-th component (start by 0)
19+
- \_\_len\_\_() : gets the size / length of the vector (number of components)
20+
- euclidLength() : returns the eulidean length of the vector.
21+
- operator + : vector addition
22+
- operator - : vector subtraction
23+
- operator * : scalar multiplication and dot product
24+
- copy() : copies this vector and returns it.
25+
- changeComponent(pos,value) : changes the specified component.
26+
27+
- function zeroVector(dimension)
28+
- returns a zero vector of 'dimension'
29+
- function unitBasisVector(dimension,pos)
30+
- returns a unit basis vector with a One at index 'pos' (indexing at 0)
31+
- function axpy(scalar,vector1,vector2)
32+
- computes the axpy operation
3333
- function randomVector(N,a,b)
3434
- returns a random vector of size N, with random integer components between 'a' and 'b'.
3535

3636
### class Matrix
3737
-
3838
- This class represents a matrix of arbitrary size and operations on it.
3939

40-
**Overview about the methods:**
41-
42-
- \_\_str\_\_() : returns a string representation
43-
- operator * : implements the matrix vector multiplication
44-
implements the matrix-scalar multiplication.
45-
- changeComponent(x,y,value) : changes the specified component.
46-
- component(x,y) : returns the specified component.
47-
- width() : returns the width of the matrix
40+
**Overview about the methods:**
41+
42+
- \_\_str\_\_() : returns a string representation
43+
- operator * : implements the matrix vector multiplication
44+
implements the matrix-scalar multiplication.
45+
- changeComponent(x,y,value) : changes the specified component.
46+
- component(x,y) : returns the specified component.
47+
- width() : returns the width of the matrix
4848
- height() : returns the height of the matrix
49-
- determinate() : returns the determinate of the matrix if it is square
50-
- operator + : implements the matrix-addition.
51-
- operator - _ implements the matrix-subtraction
52-
53-
- function squareZeroMatrix(N)
54-
- returns a square zero-matrix of dimension NxN
55-
- function randomMatrix(W,H,a,b)
56-
- returns a random matrix WxH with integer components between 'a' and 'b'
49+
- determinate() : returns the determinate of the matrix if it is square
50+
- operator + : implements the matrix-addition.
51+
- operator - _ implements the matrix-subtraction
52+
53+
- function squareZeroMatrix(N)
54+
- returns a square zero-matrix of dimension NxN
55+
- function randomMatrix(W,H,a,b)
56+
- returns a random matrix WxH with integer components between 'a' and 'b'
5757
---
5858

59-
## Documentation
59+
## Documentation
6060

6161
This module uses docstrings to enable the use of Python's in-built `help(...)` function.
6262
For instance, try `help(Vector)`, `help(unitBasisVector)`, and `help(CLASSNAME.METHODNAME)`.
6363

6464
---
6565

66-
## Usage
66+
## Usage
6767

6868
Import the module `lib.py` from the **src** directory into your project.
69-
Alternatively, you can directly use the Python bytecode file `lib.pyc`.
69+
Alternatively, you can directly use the Python bytecode file `lib.pyc`.
7070

7171
---
7272

73-
## Tests
73+
## Tests
7474

7575
`src/tests.py` contains Python unit tests which can be run with `python3 -m unittest -v`.

machine_learning/gradient_boosting_regressor.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
predict house price.
44
"""
55

6-
import pandas as pd
76
import matplotlib.pyplot as plt
7+
import pandas as pd
88
from sklearn.datasets import load_boston
9-
from sklearn.metrics import mean_squared_error, r2_score
109
from sklearn.ensemble import GradientBoostingRegressor
10+
from sklearn.metrics import mean_squared_error, r2_score
1111
from sklearn.model_selection import train_test_split
1212

1313

@@ -42,10 +42,7 @@ def main():
4242
training_score = model.score(X_train, y_train).round(3)
4343
test_score = model.score(X_test, y_test).round(3)
4444
print("Training score of GradientBoosting is :", training_score)
45-
print(
46-
"The test score of GradientBoosting is :",
47-
test_score
48-
)
45+
print("The test score of GradientBoosting is :", test_score)
4946
# Let us evaluation the model by finding the errors
5047
y_pred = model.predict(X_test)
5148

@@ -57,8 +54,7 @@ def main():
5754
# So let's run the model against the test data
5855
fig, ax = plt.subplots()
5956
ax.scatter(y_test, y_pred, edgecolors=(0, 0, 0))
60-
ax.plot([y_test.min(), y_test.max()],
61-
[y_test.min(), y_test.max()], "k--", lw=4)
57+
ax.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], "k--", lw=4)
6258
ax.set_xlabel("Actual")
6359
ax.set_ylabel("Predicted")
6460
ax.set_title("Truth vs Predicted")

maths/prime_sieve_eratosthenes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
Sieve of Eratosthenes
55
66
Input : n =10
7-
Output: 2 3 5 7
7+
Output: 2 3 5 7
88
99
Input : n = 20
10-
Output: 2 3 5 7 11 13 17 19
10+
Output: 2 3 5 7 11 13 17 19
1111
1212
you can read in detail about this at
1313
https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

project_euler/problem_11/grid.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
1818
20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
1919
20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
20-
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48
20+
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48

project_euler/problem_99/base_exp.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -997,4 +997,4 @@
997997
672276,515708
998998
325361,545187
999999
172115,573985
1000-
13846,725685
1000+
13846,725685

project_euler/project_euler_answers.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2899,4 +2899,4 @@
28992899
725,
29002900
"4598797036650685"
29012901
]
2902-
]
2902+
]

sorts/normal_distribution_quick_sort.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ The array elements are taken from a Standard Normal Distribution , having mean =
1313

1414
```python
1515

16-
>>> import numpy as np
16+
>>> import numpy as np
1717
>>> from tempfile import TemporaryFile
18-
>>> outfile = TemporaryFile()
18+
>>> outfile = TemporaryFile()
1919
>>> p = 100 # 100 elements are to be sorted
2020
>>> mu, sigma = 0, 1 # mean and standard deviation
2121
>>> X = np.random.normal(mu, sigma, p)
@@ -34,7 +34,7 @@ The array elements are taken from a Standard Normal Distribution , having mean =
3434
>>> s = np.random.normal(mu, sigma, p)
3535
>>> count, bins, ignored = plt.hist(s, 30, normed=True)
3636
>>> plt.plot(bins , 1/(sigma * np.sqrt(2 * np.pi)) *np.exp( - (bins - mu)**2 / (2 * sigma**2) ),linewidth=2, color='r')
37-
>>> plt.show()
37+
>>> plt.show()
3838

3939
```
4040

@@ -52,15 +52,15 @@ The array elements are taken from a Standard Normal Distribution , having mean =
5252

5353
--
5454

55-
## Plotting the function for Checking 'The Number of Comparisons' taking place between Normal Distribution QuickSort and Ordinary QuickSort
55+
## Plotting the function for Checking 'The Number of Comparisons' taking place between Normal Distribution QuickSort and Ordinary QuickSort
5656

5757
```python
5858
>>>import matplotlib.pyplot as plt
5959

60-
60+
6161
# Normal Disrtibution QuickSort is red
6262
>>> plt.plot([1,2,4,16,32,64,128,256,512,1024,2048],[1,1,6,15,43,136,340,800,2156,6821,16325],linewidth=2, color='r')
63-
63+
6464
#Ordinary QuickSort is green
6565
>>> plt.plot([1,2,4,16,32,64,128,256,512,1024,2048],[1,1,4,16,67,122,362,949,2131,5086,12866],linewidth=2, color='g')
6666

@@ -73,4 +73,3 @@ The array elements are taken from a Standard Normal Distribution , having mean =
7373

7474

7575
------------------
76-

0 commit comments

Comments
 (0)