Skip to content

Commit eb590cb

Browse files
authored
Merge pull request #2 from TheAlgorithms/master
adding jaccard similarity (TheAlgorithms#1270)
2 parents b33ae00 + 07f04a2 commit eb590cb

File tree

411 files changed

+20280
-4580
lines changed

Some content is hidden

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

411 files changed

+20280
-4580
lines changed

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: TheAlgorithms
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: ['http://paypal.me/TheAlgorithms/1000', 'https://donorbox.org/thealgorithms']

.github/stale.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Number of days of inactivity before an issue becomes stale
2+
daysUntilStale: 30
3+
# Number of days of inactivity before a stale issue is closed
4+
daysUntilClose: 7
5+
# Issues with these labels will never be considered stale
6+
exemptLabels:
7+
- bug
8+
- help wanted
9+
- OK to merge
10+
# Label to use when marking an issue as stale
11+
staleLabel: wontfix
12+
# Comment to post when marking an issue as stale. Set to `false` to disable
13+
markComment: >
14+
This issue has been automatically marked as stale because it has not had
15+
recent activity. It will be closed if no further activity occurs. Thank you
16+
for your contributions.
17+
# Comment to post when closing a stale issue. Set to `false` to disable
18+
closeComment: true

.gitignore

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ __pycache__/
77
*.so
88

99
# Distribution / packaging
10-
.vscode/
1110
.Python
12-
env/
1311
build/
1412
develop-eggs/
1513
dist/
@@ -21,9 +19,11 @@ lib64/
2119
parts/
2220
sdist/
2321
var/
22+
wheels/
2423
*.egg-info/
2524
.installed.cfg
2625
*.egg
26+
MANIFEST
2727

2828
# PyInstaller
2929
# Usually these files are written by a python script from a template
@@ -43,8 +43,9 @@ htmlcov/
4343
.cache
4444
nosetests.xml
4545
coverage.xml
46-
*,cover
46+
*.cover
4747
.hypothesis/
48+
.pytest_cache/
4849

4950
# Translations
5051
*.mo
@@ -53,6 +54,7 @@ coverage.xml
5354
# Django stuff:
5455
*.log
5556
local_settings.py
57+
db.sqlite3
5658

5759
# Flask stuff:
5860
instance/
@@ -67,7 +69,7 @@ docs/_build/
6769
# PyBuilder
6870
target/
6971

70-
# IPython Notebook
72+
# Jupyter Notebook
7173
.ipynb_checkpoints
7274

7375
# pyenv
@@ -76,18 +78,32 @@ target/
7678
# celery beat schedule file
7779
celerybeat-schedule
7880

79-
# dotenv
80-
.env
81+
# SageMath parsed files
82+
*.sage.py
8183

82-
# virtualenv
84+
# Environments
85+
.env
86+
.venv
87+
env/
8388
venv/
8489
ENV/
90+
env.bak/
91+
venv.bak/
8592

8693
# Spyder project settings
8794
.spyderproject
95+
.spyproject
8896

8997
# Rope project settings
9098
.ropeproject
91-
.idea
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/
105+
92106
.DS_Store
93-
.try
107+
.idea
108+
.try
109+
.vscode/

.lgtm.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.travis.yml

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
language: python
2+
dist: xenial # required for Python >= 3.7
3+
python: 3.7
24
cache: pip
3-
python:
4-
- 2.7
5-
- 3.6
6-
#- nightly
7-
#- pypy
8-
#- pypy3
9-
matrix:
10-
allow_failures:
11-
- python: nightly
12-
- python: pypy
13-
- python: pypy3
14-
install:
15-
#- pip install -r requirements.txt
16-
- pip install flake8 # pytest # add another testing frameworks later
5+
before_install: pip install --upgrade pip setuptools
6+
install: pip install -r requirements.txt
177
before_script:
18-
# stop the build if there are Python syntax errors or undefined names
19-
- flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics
20-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
21-
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
8+
- black --check . || true
9+
- flake8 . --count --select=E9,F4,F63,F7,F82 --show-source --statistics
2210
script:
23-
- true # pytest --capture=sys # add other tests here
24-
notifications:
25-
on_success: change
26-
on_failure: change # `always` will be the setting once code changes slow down
11+
- scripts/validate_filenames.py # no uppercase, no spaces, in a directory
12+
- mypy --ignore-missing-imports .
13+
- pytest . --doctest-modules
14+
after_success:
15+
- scripts/build_directory_md.py > DIRECTORY.md
16+
- cat DIRECTORY.md

.vs/Python/v15/.suo

-16.5 KB
Binary file not shown.

.vs/slnx.sqlite

-172 KB
Binary file not shown.

CONTRIBUTING.md

Lines changed: 72 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Befo
1010

1111
We are very happy that you consider implementing algorithms and data structure for others! This repository is referenced and used by learners from all over the globe. Being one of our contributors, you agree and confirm that:
1212

13-
- your 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) once your pull request is merged
16-
- you submitted work fulfils or mostly fulfils our styles and standards
15+
- Your work will be distributed under [MIT License](License) once your pull request is merged
16+
- You submitted work fulfils or mostly fulfils our styles and standards
1717

1818
**New implementation** is welcome! For example, new solutions for a problem, different representations for a graph data structure or algorithm designs with different complexity.
1919

@@ -23,19 +23,38 @@ We are very happy that you consider implementing algorithms and data structure f
2323

2424
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

26+
Your contribution will be tested by our [automated testing on Travis CI](https://travis-ci.org/TheAlgorithms/Python/pull_requests) to save time and mental energy. After you have submitted your pull request, you should see the Travis tests start to run at the bottom of your submission page. If those tests fail, then click on the ___details___ button try to read through the Travis 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.
27+
2628
#### Coding Style
2729

2830
We want your work to be readable by others; therefore, we encourage you to note the following:
2931

30-
- Please write in Python 3.x.
32+
- Please write in Python 3.7+. __print()__ is a function in Python 3 so __print "Hello"__ will _not_ work but __print("Hello")__ will.
33+
34+
- Please focus hard on naming of functions, classes, and variables. Help your reader by using __descriptive names__ that can help you to remove redundant comments.
35+
- Single letter variable names are _old school_ so please avoid them unless their life only spans a few lines.
36+
- Expand acronyms because __gcd()__ is hard to understand but __greatest_common_divisor()__ is not.
37+
- Please follow the [Python Naming Conventions](https://pep8.org/#prescriptive-naming-conventions) so variable_names and function_names should be lower_case, CONSTANTS in UPPERCASE, ClassNames should be CamelCase, etc.
38+
39+
- We encourage the use of Python [f-strings](https://realpython.com/python-f-strings/#f-strings-a-new-and-improved-way-to-format-strings-in-python) where the make the code easier to read.
3140

32-
- If you know [PEP 8](https://www.python.org/dev/peps/pep-0008/) already, you will have no problem in coding style, though we do not follow it strictly. Read the remaining section and have fun coding!
41+
- Please consider running [__psf/black__](https://github.com/python/black) on your Python file(s) before submitting your pull request. This is not yet a requirement but it does make your code more readable and automatically aligns it with much of [PEP 8](https://www.python.org/dev/peps/pep-0008/). There are other code formatters (autopep8, yapf) but the __black__ style is now the recommendation of the Python Core Team. To use it,
42+
```bash
43+
pip3 install black # only required the first time
44+
black .
45+
```
3346

34-
- Always use 4 spaces to indent.
47+
- All submissions will need to pass the test __flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics__ before they will be accepted so if possible, try this test locally on your Python file(s) before submitting your pull request.
48+
```bash
49+
pip3 install flake8 # only required the first time
50+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
51+
```
3552

36-
- Original code submission requires comments to describe your work.
53+
- Original code submission require docstrings or comments to describe your work.
3754

38-
- More on comments and docstrings:
55+
- More on docstrings and comments:
56+
57+
If you are using a Uncyclopedia article or some other source material to create your algorithm, please add the URL in a docstring or comment to help your reader.
3958

4059
The following are considered to be bad and may be requested to be improved:
4160

@@ -45,80 +64,90 @@ We want your work to be readable by others; therefore, we encourage you to note
4564

4665
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.
4766

48-
*Sometimes, docstrings are avoided.* This will happen if you are using some editors and not careful with indentation:
67+
We encourage you to put docstrings inside your functions but please pay attention to indentation of docstrings. The following is acceptable in this case:
4968

5069
```python
70+
def sumab(a, b):
71+
"""
72+
This function returns the sum of two integers a and b
73+
Return: a + b
5174
"""
52-
This function sums a and b
53-
"""
54-
def sum(a, b):
5575
return a + b
5676
```
5777

58-
However, if you insist to use docstrings, we encourage you to put docstrings inside functions. Also, please pay attention to indentation to docstrings. The following is acceptable in this case:
78+
- Write tests (especially [__doctests__](https://docs.python.org/3/library/doctest.html)) to illustrate and verify your work. We highly encourage the use of _doctests on all functions_.
5979

6080
```python
6181
def sumab(a, b):
6282
"""
63-
This function sums two integers a and b
64-
Return: a + b
65-
"""
83+
This function returns the sum of two integers a and b
84+
Return: a + b
85+
>>> sum(2, 2)
86+
4
87+
>>> sum(-2, 3)
88+
1
89+
>>> sum(4.9, 6.1)
90+
10.0
91+
"""
6692
return a + b
6793
```
6894

69-
- `lambda`, `map`, `filter`, `reduce` and complicated list comprehension are welcome and acceptable to demonstrate the power of Python, as long as they are simple enough to read.
70-
71-
- This is arguable: **write comments** and assign appropriate variable names, so that the code is easy to read!
72-
73-
- Write tests to illustrate your work.
95+
These doctests will be run by pytest as part of our automated testing so please try to run your doctests locally and make sure that they are found and pass:
96+
```bash
97+
python3 -m doctest -v my_submission.py
98+
```
7499

75-
The following "testing" approaches are not encouraged:
100+
The use of the Python builtin __input()__ function is **not** encouraged:
76101

77102
```python
78-
input('Enter your input:')
103+
input('Enter your input:')
79104
# Or even worse...
80-
input = eval(raw_input("Enter your input: "))
105+
input = eval(input("Enter your input: "))
81106
```
82107

83-
Please write down your test case, like the following:
108+
However, if your code uses __input()__ then we encourage you to gracefully deal with leading and trailing whitespace in user input by adding __.strip()__ as in:
84109

85110
```python
86-
def sumab(a, b):
87-
return a + b
88-
# Write tests this way:
89-
print(sumab(1,2)) # 1+2 = 3
90-
print(sumab(6,4)) # 6+4 = 10
91-
# Or this way:
92-
print("1 + 2 = ", sumab(1,2)) # 1+2 = 3
93-
print("6 + 4 = ", sumab(6,4)) # 6+4 = 10
111+
starting_value = int(input("Please enter a starting value: ").strip())
94112
```
113+
114+
The use of [Python type hints](https://docs.python.org/3/library/typing.html) is encouraged for function parameters and return values. Our automated testing will run [mypy](http://mypy-lang.org) so run that locally before making your submission.
115+
```python
116+
def sumab(a: int, b: int) --> int:
117+
pass
118+
```
119+
120+
- [__list comprehensions and generators__](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions) are preferred over the use of `lambda`, `map`, `filter`, `reduce` but the important thing is to demonstrate the power of Python in code that is easy to read and maintain.
95121

96-
- Avoid importing external libraries for basic algorithms. Use those libraries for complicated algorithms.
122+
- Avoid importing external libraries for basic algorithms. Only use those libraries for complicated algorithms.
123+
124+
- If you need a third party module that is not in the file __requirements.txt__, please add it to that file as part of your submission.
97125

98126
#### Other Standard While Submitting Your Work
99127

100-
- File extension for code should be `.py`.
128+
- File extension for code should be `.py`. Jupiter notebook files are acceptable in machine learning algorithms.
101129

102-
- Please file your work to let others use it in the future. Here are the examples that are acceptable:
130+
- Please avoid creating new directories if at all possible. Try to fit your work into the existing directory structue.
103131

104-
- Camel cases
105-
- `-` Hyphenated names
106-
- `_` Underscore-separated names
132+
- Strictly use snake_case (underscore_separated) in your file_name, as it will be easy to parse in future using scripts.
107133

108134
If possible, follow the standard *within* the folder you are submitting to.
109135

110136
- If you have modified/added code work, make sure the code compiles before submitting.
111137

112-
- If you have modified/added documentation work, make sure your language is concise and contains no grammar mistake.
138+
- If you have modified/added documentation work, ensure your language is concise and contains no grammar errors.
139+
140+
- Do not update the README.md or DIRECTORY.md file which will be periodically autogenerated by our Travis CI processes.
113141

114142
- Add a corresponding explanation to [Algorithms-Explanation](https://github.com/TheAlgorithms/Algorithms-Explanation) (Optional but recommended).
115143

144+
- All submissions will be tested with [__mypy__](http://www.mypy-lang.org) so we encourage to add [__Python type hints__](https://docs.python.org/3/library/typing.html) where it makes sense to do so.
145+
116146
- Most importantly,
117147

118-
- **be consistent with this guidelines while submitting.**
119-
- **join** [Gitter](https://gitter.im/TheAlgorithms) **now!**
148+
- **Be consistent in the use of these guidelines when submitting.**
149+
- **Join** [Gitter](https://gitter.im/TheAlgorithms) **now!**
120150
- Happy coding!
121151

122152

123-
124153
Writer [@poyea](https://github.com/poyea), Jun 2019.

0 commit comments

Comments
 (0)