Skip to content

Commit

Permalink
Merge pull request #2 from TheAlgorithms/master
Browse files Browse the repository at this point in the history
adding jaccard similarity (TheAlgorithms#1270)
  • Loading branch information
fengjixuchui authored Oct 4, 2019
2 parents b33ae00 + 07f04a2 commit eb590cb
Show file tree
Hide file tree
Showing 411 changed files with 20,280 additions and 4,580 deletions.
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: TheAlgorithms
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ['http://paypal.me/TheAlgorithms/1000', 'https://donorbox.org/thealgorithms']
18 changes: 18 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 30
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- bug
- help wanted
- OK to merge
# Label to use when marking an issue as stale
staleLabel: wontfix
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: true
34 changes: 25 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ __pycache__/
*.so

# Distribution / packaging
.vscode/
.Python
env/
build/
develop-eggs/
dist/
Expand All @@ -21,9 +19,11 @@ lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
Expand All @@ -43,8 +43,9 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
*,cover
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
Expand All @@ -53,6 +54,7 @@ coverage.xml
# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
Expand All @@ -67,7 +69,7 @@ docs/_build/
# PyBuilder
target/

# IPython Notebook
# Jupyter Notebook
.ipynb_checkpoints

# pyenv
Expand All @@ -76,18 +78,32 @@ target/
# celery beat schedule file
celerybeat-schedule

# dotenv
.env
# SageMath parsed files
*.sage.py

# virtualenv
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject
.idea

# mkdocs documentation
/site

# mypy
.mypy_cache/

.DS_Store
.try
.idea
.try
.vscode/
12 changes: 0 additions & 12 deletions .lgtm.yml

This file was deleted.

34 changes: 12 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
language: python
dist: xenial # required for Python >= 3.7
python: 3.7
cache: pip
python:
- 2.7
- 3.6
#- nightly
#- pypy
#- pypy3
matrix:
allow_failures:
- python: nightly
- python: pypy
- python: pypy3
install:
#- pip install -r requirements.txt
- pip install flake8 # pytest # add another testing frameworks later
before_install: pip install --upgrade pip setuptools
install: pip install -r requirements.txt
before_script:
# stop the build if there are Python syntax errors or undefined names
- flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- black --check . || true
- flake8 . --count --select=E9,F4,F63,F7,F82 --show-source --statistics
script:
- true # pytest --capture=sys # add other tests here
notifications:
on_success: change
on_failure: change # `always` will be the setting once code changes slow down
- scripts/validate_filenames.py # no uppercase, no spaces, in a directory
- mypy --ignore-missing-imports .
- pytest . --doctest-modules
after_success:
- scripts/build_directory_md.py > DIRECTORY.md
- cat DIRECTORY.md
Binary file removed .vs/Python/v15/.suo
Binary file not shown.
Binary file removed .vs/slnx.sqlite
Binary file not shown.
115 changes: 72 additions & 43 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Befo

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:

- your did your work - no plagiarism allowed
- You did your work - no plagiarism allowed
- Any plagiarized work will not be merged.
- your work will be distributed under [MIT License](License) once your pull request is merged
- you submitted work fulfils or mostly fulfils our styles and standards
- Your work will be distributed under [MIT License](License) once your pull request is merged
- You submitted work fulfils or mostly fulfils our styles and standards

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

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

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.

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.

#### Coding Style

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

- Please write in Python 3.x.
- Please write in Python 3.7+. __print()__ is a function in Python 3 so __print "Hello"__ will _not_ work but __print("Hello")__ will.

- 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.
- Single letter variable names are _old school_ so please avoid them unless their life only spans a few lines.
- Expand acronyms because __gcd()__ is hard to understand but __greatest_common_divisor()__ is not.
- 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.

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

- 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!
- 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,
```bash
pip3 install black # only required the first time
black .
```

- Always use 4 spaces to indent.
- 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.
```bash
pip3 install flake8 # only required the first time
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
```

- Original code submission requires comments to describe your work.
- Original code submission require docstrings or comments to describe your work.

- More on comments and docstrings:
- More on docstrings and comments:

If you are using a Wikipedia article or some other source material to create your algorithm, please add the URL in a docstring or comment to help your reader.

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

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

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.

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

```python
def sumab(a, b):
"""
This function returns the sum of two integers a and b
Return: a + b
"""
This function sums a and b
"""
def sum(a, b):
return a + b
```

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:
- 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_.

```python
def sumab(a, b):
"""
This function sums two integers a and b
Return: a + b
"""
This function returns the sum of two integers a and b
Return: a + b
>>> sum(2, 2)
4
>>> sum(-2, 3)
1
>>> sum(4.9, 6.1)
10.0
"""
return a + b
```

- `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.

- This is arguable: **write comments** and assign appropriate variable names, so that the code is easy to read!

- Write tests to illustrate your work.
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:
```bash
python3 -m doctest -v my_submission.py
```

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

```python
input('Enter your input:')
input('Enter your input:')
# Or even worse...
input = eval(raw_input("Enter your input: "))
input = eval(input("Enter your input: "))
```

Please write down your test case, like the following:
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:

```python
def sumab(a, b):
return a + b
# Write tests this way:
print(sumab(1,2)) # 1+2 = 3
print(sumab(6,4)) # 6+4 = 10
# Or this way:
print("1 + 2 = ", sumab(1,2)) # 1+2 = 3
print("6 + 4 = ", sumab(6,4)) # 6+4 = 10
starting_value = int(input("Please enter a starting value: ").strip())
```

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.
```python
def sumab(a: int, b: int) --> int:
pass
```

- [__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.

- Avoid importing external libraries for basic algorithms. Use those libraries for complicated algorithms.
- Avoid importing external libraries for basic algorithms. Only use those libraries for complicated algorithms.

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

#### Other Standard While Submitting Your Work

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

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

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

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

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

- If you have modified/added documentation work, make sure your language is concise and contains no grammar mistake.
- If you have modified/added documentation work, ensure your language is concise and contains no grammar errors.

- Do not update the README.md or DIRECTORY.md file which will be periodically autogenerated by our Travis CI processes.

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

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

- Most importantly,

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



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

0 comments on commit eb590cb

Please sign in to comment.