Skip to content

Commit 4f53f94

Browse files
authored
Merge branch 'master' into improve-linear-search-edge-case
2 parents 96b4f34 + a4c1df1 commit 4f53f94

372 files changed

Lines changed: 16613 additions & 1673 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
* [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html).
1818
* [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing.
1919
* [ ] All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
20-
* [ ] If this pull request resolves one or more open issues then the description above includes the issue number(s) with a [closing keyword](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue): "Fixes #ISSUE-NUMBER".
20+
* [ ] If this pull request resolves one or more open issues, then the description above includes the issue number(s) with a [closing keyword](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue): "Fixes #ISSUE-NUMBER".

.github/skills/new-pull-request/SKILL.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ hand. A hand-modified `uv.lock` makes the `algorithms-keeper` bot close the pull
1919
request as invalid, and even a repo maintainer cannot undo that.
2020

2121
Always check at least one Markdown checkbox in the pull request description (the "Describe your change" section), or the
22-
`algorithms-keeper` bot will close the pull request as invalid. Any repo maintainer can undo this if you @mention them on the closed pull request.
22+
`algorithms-keeper` bot will close the pull request as invalid — and it does
23+
this *before* a human reads the PR, so a genuinely good change gets closed for a
24+
formatting reason. This applies to **every** pull request, including CI, docs,
25+
and tooling changes that are not algorithms: tick the boxes that genuinely apply
26+
so the body is never submitted with all boxes empty. Any repo maintainer can
27+
undo this if you @mention them on the closed pull request, but re-opening is
28+
often unreliable, so it is far better to get it right the first time.
2329

2430
### 1. Before contributing / Is this an algorithm?
2531

@@ -55,3 +61,15 @@ Always check at least one Markdown checkbox in the pull request description (the
5561
- [ ] At least one **Wikipedia (or equivalent) URL** documenting the algorithm.
5662
- [ ] Docstring explains what the function does and its parameters/returns.
5763
- [ ] No unnecessary third-party dependencies.
64+
65+
## Before you click "Create pull request"
66+
67+
This is the final gate. Do not open the pull request until every item here is true:
68+
69+
- [ ] At least one Markdown checkbox in the PR description is checked. **Verify
70+
this by re-reading the rendered body** — if every box is still `- [ ]`, the
71+
`algorithms-keeper` bot will auto-close the PR before any human sees it.
72+
Check the boxes that genuinely apply to this change; never submit an
73+
all-empty checklist, even for a CI, docs, or tooling PR.
74+
- [ ] The branch is not `master`, and `master` is synced with `upstream/master`.
75+
- [ ] `uv.lock` was not hand-edited.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Skill: Review an open issue for TheAlgorithms/Python
2+
3+
Triage an open issue — most often one carrying the `bug` label — **together with
4+
every pull request attached to it**, and produce a verdict a maintainer can act on
5+
without re-doing the work. The goal is a review that any triager (human or AI) can
6+
run the same way every time, and that ends in an explicit list of `Closes #NNNNN`
7+
lines the maintainer can paste into a merge commit.
8+
9+
This repo exists to **teach visitors to fix bugs by doing**. So the default is to
10+
merge adequate existing contributor work, not to open a fresh PR that races them.
11+
Only open your own PR when no attached PR adequately solves the issue.
12+
13+
## How to run this skill
14+
15+
### 1. Reproduce before you trust the report
16+
17+
- Check out current `master` and actually **run the failing case** from the issue.
18+
- If it reproduces, say so and paste the minimal reproducer (inputs → observed
19+
output, e.g. `nan` + a `RuntimeWarning`).
20+
- If you **cannot** confirm it locally — an optional dependency isn't installed,
21+
the failure needs an external service, the report is too vague — **say that
22+
explicitly rather than guessing.** "Not reproducible in a vanilla checkout"
23+
is a real, useful verdict.
24+
25+
### 2. Classify the issue
26+
27+
Sort each issue into one bucket and act accordingly:
28+
29+
- **Confirmed bug with an adequate open PR** → recommend the specific PR to merge.
30+
- **Confirmed bug, no adequate PR** → open a new PR yourself (see step 5).
31+
- **Not a bug / working-as-intended** → recommend closing, and explain why (e.g.
32+
binary search returning *an* index of a duplicate is correct, not a defect).
33+
- **Feature request mislabeled as a bug** → recommend dropping the `bug` label; do
34+
**not** close it as a bug.
35+
- **Too vague / needs reporter info** → comment **on the issue itself** asking for
36+
the one concrete thing missing (a file path, a traceback, a reproducer), and note
37+
it should be closed if no answer arrives.
38+
- **Environment / optional-dependency, not an algorithm defect** → note it needs
39+
someone with that environment; it is not fixable in a vanilla checkout.
40+
41+
### 3. Examine every attached PR — pick one, name the duplicates
42+
43+
For a bug with several open PRs:
44+
45+
- **Verify each fix's doctest values numerically** against a trusted reference
46+
(`scipy`, `numpy.linalg`, `geopy`, or a brute-force check over random inputs).
47+
Don't take a doctest's word for it — confirm the number.
48+
- Prefer the **first-in PR with the smallest correct diff** that follows repo
49+
convention (doctests over new test files, `raise` over `assert`, no unrelated
50+
reindentation or churn of clean doctests into floating-point noise).
51+
- **Reject out-of-scope "fixes"** — e.g. swapping a real divide-by-zero for a
52+
`1e-15` magic constant makes results implementation-defined. Fix the issue, not
53+
more.
54+
- Identify the byte-for-byte **duplicates** so the maintainer can close them with
55+
thanks in the same action.
56+
57+
### 4. Emit the verdict — fixed output shape
58+
59+
Post one comment that a maintainer can act on directly. For each issue give a
60+
one-line rationale and the exact autoclose line. Two formatting rules matter a lot
61+
to human maintainers scanning the thread:
62+
63+
- **Start every line that references an issue or PR with a Markdown list marker
64+
(`-` or `* `).** GitHub-flavored Markdown only autolinks `#NNNNN` inside a list,
65+
and those autolinks are colored — **purple = merged, red = closed, green = open**
66+
so the maintainer can see merge/close progress at a glance. A bare `#14813` at the
67+
start of a line does not autolink.
68+
- **Merging a PR that closes an issue also closes the issue's other open PRs**, so
69+
fold the duplicates into one autoclose statement rather than listing the winner
70+
alone:
71+
72+
```text
73+
* #14813 — 3x3 inverse returns the transpose → merge #14821
74+
(Closes #14813, Closes #14840, Closes #15045)
75+
```
76+
77+
Recommended shape:
78+
79+
```text
80+
## Confirmed bugs with an adequate open PR — merge
81+
* #<issue> — <one-line what/why> → merge #<pr> (Closes #<issue>, Closes #<dupe>, …)
82+
83+
## Not a bug / not merge-ready
84+
* #<issue> — <feature-request → relabel | needs cleanup | needs a human call>
85+
86+
## Summary — lines to add
87+
* Closes #<issue> → #<pr>
88+
```
89+
90+
### 5. When you must open your own PR
91+
92+
If no attached PR is adequate, open one — but let the contributors keep the credit
93+
where their work was close. Use autoclose keywords in the **commit message body**
94+
so the merge closes the issue *and* the superseded PRs:
95+
96+
```text
97+
Fixes #12233
98+
Fixes #12262
99+
Fixes #13635
100+
```
101+
102+
Follow the [`new-pull-request`](../new-pull-request/SKILL.md) skill for the
103+
mechanics (synced `master`, named branch, checked description box, untouched
104+
`uv.lock`).
105+
106+
## Tone
107+
108+
Be specific and kind. Name the exact PR and the exact reason, credit the
109+
contributor by handle, and offer runners-up detailed feedback so they learn — the
110+
point of the repo is that people come back and fix the next one.

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ jobs:
2020
with:
2121
python-version-file: .python-version
2222
allow-prereleases: true
23+
# keras needs hdf5 on pre-release Python.
24+
- run: |
25+
if [ "$(python -c 'import sys; print(sys.version_info.releaselevel)')" != "final" ]; then
26+
sudo apt-get update -qq
27+
sudo apt-get install --yes libhdf5-dev
28+
fi
2329
- run: uv sync --group=test
2430
- name: Run tests
2531
# opencv-python is gated out on 3.14t (no cp314t wheel yet), so skip the

.github/workflows/hacktoberfest_prep.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ jobs:
8080
fi
8181
git config --global user.name "$GITHUB_ACTOR"
8282
git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"
83+
# `actions/checkout` runs with `persist-credentials: false`, so git has
84+
# no token to authenticate the push below (it fails with
85+
# `fatal: could not read Username for 'https://github.com'`). Wire the
86+
# bundled `gh` in as git's credential helper so `git push` reuses
87+
# GH_TOKEN — no third-party action and no token baked into the remote URL.
88+
gh auth setup-git
8389
git switch -c "$BRANCH"
8490
git add docs/hacktober_2026_prep.md
8591
git commit -m "chore: refresh Hacktoberfest 2026 prep tracker"

.github/workflows/sphinx.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ jobs:
3333
with:
3434
python-version-file: .python-version
3535
allow-prereleases: true
36+
# keras needs hdf5 on pre-release Python.
37+
- run: |
38+
if [ "$(python -c 'import sys; print(sys.version_info.releaselevel)')" != "final" ]; then
39+
sudo apt-get update -qq
40+
sudo apt-get install --yes libhdf5-dev
41+
fi
3642
- run: uv sync --group=docs
3743
- uses: actions/configure-pages@v6
3844
- run: uv run sphinx-build -c docs . docs/_build/html

.github/zizmor.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ rules:
22
excessive-permissions:
33
disable: true
44
unpinned-uses:
5-
disable: true
6-
# config:
7-
# policies:
8-
# actions/*: ref-pin
5+
config:
6+
policies:
7+
"*": ref-pin

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ repos:
3434
- id: pyproject-fmt
3535

3636
- repo: https://github.com/astral-sh/ruff-pre-commit
37-
rev: v0.16.6
37+
rev: v0.16.7
3838
hooks:
3939
- id: ruff-check
4040
- id: ruff-format
4141

4242
- repo: https://github.com/rvben/rumdl-pre-commit
43-
rev: v0.2.69
43+
rev: v0.2.73
4444
hooks:
4545
- id: rumdl-fmt
4646
- id: rumdl
@@ -55,7 +55,7 @@ repos:
5555
pass_filenames: false
5656

5757
- repo: https://github.com/astral-sh/uv-pre-commit
58-
rev: 0.12.11
58+
rev: 0.12.13
5959
hooks:
6060
- id: uv-lock
6161

CONTRIBUTING.md

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
# Contributing guidelines
1+
# Contributing Guidelines
22

3-
## Before contributing
3+
## Before Contributing
44

5-
Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Before submitting your pull requests, please ensure that you __read the whole guidelines__. If you have any doubts about the contributing guide, please feel free to [state it clearly in an issue](https://github.com/TheAlgorithms/Python/issues/new) or ask the community on [Gitter](https://gitter.im/TheAlgorithms/community).
5+
Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Before submitting your pull requests, please ensure that you __read the entire guidelines__. If you have any doubts about the contributing guide, please feel free to [state them clearly in an issue](https://github.com/TheAlgorithms/Python/issues/new) or ask the community on [Gitter](https://gitter.im/TheAlgorithms/community).
66

77
## Contributing
88

99
### Contributor
1010

1111
We are delighted that you are considering implementing algorithms and data structures for others! This repository is referenced and used by learners from all over the globe. By being one of our contributors, you agree and confirm that:
1212

13-
- You did your work - no plagiarism allowed.
13+
- You did your work no plagiarism allowed.
1414
- Any plagiarized work will not be merged.
15-
- Your work will be distributed under [MIT License](LICENSE.md) once your pull request is merged.
15+
- Your work will be distributed under the [MIT License](LICENSE.md) once your pull request is merged.
1616
- Your submitted work fulfills or mostly fulfills our styles and standards.
1717

18-
__New implementation__ is welcome! For example, new solutions for a problem, different representations for a graph data structure or algorithm designs with different complexity, but __identical implementation__ of an existing implementation is not allowed. Please check whether the solution is already implemented or not before submitting your pull request.
18+
__New implementations__ are welcome! For example, new solutions for a problem, different representations for a graph data structure, or algorithm designs with different complexities. However, __identical implementations__ of an existing one are not allowed. Please check whether the solution is already implemented before submitting your pull request.
1919

2020
__Improving comments__ and __writing proper tests__ are also highly welcome.
2121

2222
### Contribution
2323

24-
We appreciate any contribution, from fixing a grammar mistake in a comment to implementing complex algorithms. Please read this section if you are contributing your work.
24+
We appreciate any contribution from fixing a grammar mistake in a comment to implementing complex algorithms. Please read this section if you are contributing your work.
2525

2626
Your contribution will be tested by our [automated testing on GitHub Actions](https://github.com/TheAlgorithms/Python/actions) to save time and mental energy. After you have submitted your pull request, you should see the GitHub Actions tests start to run at the bottom of your submission page.
2727

2828
If those tests fail, then click on the ___details___ button to read through the GitHub Actions output to understand the failure. If you do not understand, please leave a comment on your submission page, and a community member will try to help.
2929

3030
#### Issues
3131

32-
If you are interested in resolving an [open issue](https://github.com/TheAlgorithms/Python/issues), simply make a pull request with your proposed fix. __We do not assign issues in this repo__ so please do not ask for permission to work on an issue.
32+
If you are interested in resolving an [open issue](https://github.com/TheAlgorithms/Python/issues), simply make a pull request with your proposed fix. __We do not assign issues in this repo__, so please do not ask for permission to work on an issue.
3333

3434
__Do not__ create an issue to contribute an algorithm. Please submit a pull request instead.
3535

@@ -44,17 +44,31 @@ GitHub will use this tag to [auto-close the issue](https://docs.github.com/en/is
4444

4545
#### What is an Algorithm?
4646

47-
An Algorithm is one or more functions (or classes) that:
47+
An algorithm is one or more functions (or classes) that:
4848

4949
- take one or more inputs,
5050
- perform some internal calculations or data manipulations,
5151
- return one or more outputs,
52-
- have minimal side effects (Ex. `print()`, `plot()`, `read()`, `write()`).
52+
- have minimal side effects (e.g., `print()`, `plot()`, `read()`, `write()`).
5353

54-
Algorithms should be packaged in a way that makes it easy for readers to put them into larger programs.
54+
Algorithms should be packaged in a way that would make it easy for readers to integrate them into larger programs.
5555

5656
Algorithms should:
5757

58+
- have intuitive class and function names that make their purpose clear to readers,
59+
- use Python naming conventions and intuitive variable names to ease comprehension,
60+
- be flexible to take different input values,
61+
- have Python type hints for their input parameters and return values,
62+
- raise Python exceptions (`ValueError`, etc.) on erroneous input values,
63+
- have docstrings with clear explanations and/or URLs to source materials,
64+
- contain doctests that test both valid and erroneous input values,
65+
- return all calculation results instead of printing or plotting them.
66+
67+
Algorithms in this repo should not be simple how-to examples for existing Python packages. Instead, they should perform internal calculations or manipulations to convert input values into different output values.
68+
These calculations or manipulations can use data types, classes, or functions of existing Python packages, but each algorithm in this repo should add unique value.
69+
70+
#### Pre-Commit Plugin
71+
5872
- have intuitive class and function names that make their purpose clear to readers
5973
- use Python naming conventions and intuitive variable names to ease comprehension
6074
- be flexible to take different input values
@@ -67,7 +81,7 @@ Algorithms should:
6781
Algorithms in this repo should not be how-to examples for existing Python packages. Instead, they should perform internal calculations or manipulations to convert input values into different output values.
6882
Those calculations or manipulations can use data types, classes, or functions of existing Python packages, but each algorithm in this repo should add unique value.
6983

70-
#### Pre-commit plugin
84+
#### Pre-commit
7185

7286
Use [pre-commit](https://pre-commit.com/#installation) to automatically format your code to match our coding style:
7387

@@ -76,7 +90,7 @@ python3 -m pip install pre-commit # only required the first time
7690
pre-commit install
7791
```
7892

79-
That's it! The plugin will run every time you commit any changes. If any errors are found during the run, fix them and commit those changes. You can even run the plugin manually on all files:
93+
That's it! Pre-commit will run every time you commit any changes. If any errors are found during the run, fix them and commit those changes. You can even run the plugin manually on all files:
8094

8195
```bash
8296
pre-commit run --all-files --show-diff-on-failure
@@ -118,12 +132,13 @@ We want your work to be readable by others; therefore, we encourage you to note
118132
The following are considered to be bad and may be requested to be improved:
119133

120134
```python
121-
x = x + 2 # increased by 2
135+
x += 2 # increased by 2
122136
```
123137

124-
This is too trivial. Comments are expected to be explanatory. For comments, you can write them above, on, or below a line of code, as long as you are consistent within the same piece of code.
138+
This is too trivial. Comments should not merely repeat what the code already says. Comments should explain ___why___ we are doing things. Comments on the same line as code should never cause the line to wrap (> 88 characters per line).
139+
Comments which are not on the same line as code should appear ___before___ the code they describe. "First tell the reader ___why___ with comments and then show them ___how___ with code."
125140

126-
We encourage you to put docstrings inside your functions, but please pay attention to the indentation of docstrings. The following is a good example:
141+
We require you to put docstrings inside your functions, but please pay attention to the indentation of docstrings. The following is a good example:
127142

128143
```python
129144
def sum_ab(a, b):

0 commit comments

Comments
 (0)