Skip to content
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

Major syntax updates, PEP8 Compliance, enhancement suggestions, and proposed changes! #37

Merged
merged 8 commits into from
Aug 19, 2017

Conversation

IanDoarn
Copy link
Contributor

Suggestions

  • The modules.py file in each package is very redundant, users can simply do the following:
from pygorithm import string
help(string)

# Outputs
"""
Help on package pygorithm.string in pygorithm:

NAME
   pygorithm.string - Collection of string methods and functions

PACKAGE CONTENTS
   anagram
   isogram
   modules
   palindrome
   pangram

DATA
   __all__ = ['anagram', 'pangram', 'isogram', 'palindrome']

FILE
   c:\users\doarni\dev\pygorithm\pygorithm\string\__init__.py
"""
  • The get_code() functions can be removed from all files, python is not compiled so people can easily open the files up and view their source code.
  • It is extremely redundant importing inspect every time, instead the user can import that themselves and it will still act the same, it is not necessary to be in each .py file.

Example:

from pygorithm.string import palindrome
import inspect

print(inspect.getsource(palindrome))
  • The time_complexities() function can also be removed, instead this can be included in each module/.py docstrings or in the functions docstrings. When the user calls help() on the function, it will explain how they work, and give them the time complexities.

  • A sort of function to time some algorithms? We could incorperate a decorator package, users could decorate their functions with them, and see how effeciant each are!

  • Use function annotations to annotate inputs, and use a custom decorator so when a user calls methods, we can make sure their input is correct, as in checking that the input is a str, int, float, to make python act more like other languages since by default python does not check input parameters. Though this could make the source code for the functions more confusing for newcommers to python! More information: https://code.tutsplus.com/tutorials/python-3-function-annotations--cms-25689

  • package string should be changed to strings. string is a default python module, having a package shadow builtin/default modules can cause problems.

  • Decide whether or not to support Python 2.7. heap.py uses super() which is a Python 3+ builtin. Something can be added to the main init.py to check for the version thats being run. I've included from __future__ import division in some of the modules since I see that // has been used and Python 3+ you only need /. If you want to support Python 2.7 you or someone will need to rewrite heao.py!

Updates

  • data_structures
    • Updated init.py
    • graph.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Removed redundant import statments in methods
      • Updated syntaxing for PEP8 compliance
      • Updated conditional sytaxing
      • Removed camel casing from variable and parameter names
      • Updated _union() and _set_of() in WeightedGraph() class to make them private
      • Added self.forest to init() or WeightedGraph() class
      • Updated _topological_sort_rec() in TopologicalSort() class to make it private
      • Updated _check_cycle_rec() in CheckCycleDirectedGraph() class to make it private
      • Updated _check_cycle_rec() in CheckCycleUndirectedGraph() class to make it private
    • queue.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Removed redundant import statments in methods
    • linked_list.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Removed redundant import statments in methods
      • Updated conditionals and syntaxing
      • Removed redundant parenthesis around conditionals
      • Removed camel casing on variables
    • heap.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Removed redundant import statments in methods
      • Updated parent_idx, left_child_idx, right_child_idx, time_complexities to be static
      • removed unused variable 'ROOT' from heapify_down()
    • stack.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Removed redundant import statments in methods
      • Removed camel casing on methods and variables
      • Updated get_code() in Stack(object) to be static
      • Updated _isOperand(), _precedence() in InfixToPostfix() to be static and private
      • Updated get_code() to be static
      • Updated method _isOperand()
      • Removed redundant parenthesis around conditionals
    • tree.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Removed redundant import statments in methods
      • Removed redundant parenthesis around conditionals
      • Updated min_val_bst_node(), get_code()
      • Removed camel casing on variables and parameter names
  • string
    • anagram.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Fixed indentations in is_anagram()
      • Updated syntaxing for PEP8 compliance
    • palindrome.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Updated syntaxing for PEP8 compliance
      • Optimized code of is_palindrome
    • isogram.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Updated syntaxing for PEP8 compliance
      • Optimized code of is_isogram
    • pangram.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Updated syntaxing for PEP8 compliance
      • Optimized code in is_pangram
  • fibonacci
    • generator.py
      • Updated syntaxing for PEP8 compliance
      • Updated parameter name on nested function sequence(), it was shadowing outer functions parameter name
    • goldenratio.py
      • Updated syntaxing for PEP8 compliance
      • Functions no longer nested
  • math
    • lcm.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Updated syntaxing for PEP8 compliance
      • Updated code to prevent variables from shadowing method names
    • lcm_using_gcd.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Updated syntaxing for PEP8 compliance
      • Updated code to remove camel casing on parameter names
    • sieve_of_eratosthenesd.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Updated syntaxing for PEP8 compliance
      • Removed redundant parenthesis in conditionals
      • Optimized conditionals
  • searching
    • binary_search.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Updated syntaxing for PEP8 compliance
      • Updated code in binary_search
    • breadth_first_search.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Updated syntaxing for PEP8 compliance
    • depth_fist_seach.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Updated syntaxing for PEP8 compliance
      • Updated code in depth_first_search
    • linear_search.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Updated syntaxing for PEP8 compliance
      • Removed camel casing from variable and parameter names
    • quick_select.py
      • Updated docstrings at top of file
      • Updated docstrings for functions
      • Optimized import statements
      • Updated syntaxing for PEP8 compliance
      • moved nested functions out of search()

IanDoarn added 2 commits August 18, 2017 08:49
- data_structures
	- Updated __init__.py
	- graph.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Removed redundant import statments in methods
		- Updated syntaxing for PEP8 compliance
		- Updated conditional sytaxing
		- Removed camel casing from variable and parameter names
		- Updated _union() and _set_of() in WeightedGraph() class to make them private
		- Added self.forest to __init__() or WeightedGraph() class
		- Updated _topological_sort_rec() in TopologicalSort() class to make it private
		- Updated _check_cycle_rec() in CheckCycleDirectedGraph() class to make it private
		- Updated _check_cycle_rec() in CheckCycleUndirectedGraph() class to make it private
- string
	- anagram.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Fixed indentations in is_anagram()
		- Updated syntaxing for PEP8 compliance
	- palindrome.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Updated syntaxing for PEP8 compliance
		- Optimized code of is_palindrome
	- isogram.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Updated syntaxing for PEP8 compliance
		- Optimized code of is_isogram
	- pangram.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Updated syntaxing for PEP8 compliance
		- Optimized code in is_pangram
- fibonacci
	- generator.py
		- Updated syntaxing for PEP8 compliance
		- Updated parameter name on nested function sequence(), it was shadowing outer functions parameter name
	- goldenratio.py
		- Updated syntaxing for PEP8 compliance
		- Functions no longer nested
- math
	- lcm.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Updated syntaxing for PEP8 compliance
		- Updated code to prevent variables from shadowing method names
	- lcm_using_gcd.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Updated syntaxing for PEP8 compliance
		- Updated code to remove camel casing on parameter names
	- sieve_of_eratosthenesd.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Updated syntaxing for PEP8 compliance
		- Removed redundant parenthesis in conditionals
		- Optimized conditionals
- searching
	- binary_search.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Updated syntaxing for PEP8 compliance
		- Updated code in binary_search
	- breadth_first_search.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Updated syntaxing for PEP8 compliance
	- depth_fist_seach.py
	 	- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Updated syntaxing for PEP8 compliance
		- Updated code in depth_first_search
	- linear_search.py
	 	- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Updated syntaxing for PEP8 compliance
		- Removed camel casing from variable and parameter names
    - quick_select.py
        - Updated docstrings at top of file
        - Updated docstrings for functions
        - Optimized import statements
        - Updated syntaxing for PEP8 compliance
        - moved nested functions out of search()

Signed-off-by: IanDoarn <ian.doarn@zimmerbiomet.com>
    - queue.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Removed redundant import statments in methods
	- linked_list.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Removed redundant import statments in methods
		- Updated conditionals and syntaxing
		- Removed redundant parenthesis around conditionals
		- Removed camel casing on variables
	- heap.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Removed redundant import statments in methods
		- Updated parent_idx, left_child_idx, right_child_idx, time_complexities to be static
		- removed unused variable 'ROOT' from heapify_down()
	- stack.py
		- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Removed redundant import statments in methods
		- Removed camel casing on methods and variables
		- Updated get_code() in Stack(object) to be static
		- Updated _isOperand(), _precedence() in InfixToPostfix() to be static and private
		- Updated get_code() to be static
		- Updated method _isOperand()
		- Removed redundant parenthesis around conditionals
	- tree.py
	  	- Updated docstrings at top of file
		- Updated docstrings for functions
		- Optimized import statements
		- Removed redundant import statments in methods
		- Removed redundant parenthesis around conditionals
		- Updated min_val_bst_node(), get_code()
		- Removed camel casing on variables and parameter names

Signed-off-by: IanDoarn <ian.doarn@zimmerbiomet.com>
IanDoarn added 6 commits August 18, 2017 13:20
 - stack.py, binary_search.py, depth_first_search.py

Signed-off-by: IanDoarn <ian.doarn@zimmerbiomet.com>
…earch.py

Signed-off-by: IanDoarn <ian.doarn@zimmerbiomet.com>
Signed-off-by: IanDoarn <ian.doarn@zimmerbiomet.com>
…al in method __precedence()

Signed-off-by: IanDoarn <ian.doarn@zimmerbiomet.com>
# Conflicts:
#	pygorithm/data_structures/stack.py
…al in method __precedence()

Signed-off-by: IanDoarn <ian.doarn@zimmerbiomet.com>
@IanDoarn
Copy link
Contributor Author

IanDoarn commented Aug 18, 2017

After #38 issue resolution All unit tests pass. Thanks MrDupin!!!

test_data_structures

   .
----------------------------------------------------------------------
Ran 1 test in 0.002s

OK

test_fibonacci

.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

test_math

...
----------------------------------------------------------------------
Ran 3 tests in 0.002s

OK

test_searching

....
----------------------------------------------------------------------
Ran 4 tests in 0.004s

OK

test_sorting

.........
----------------------------------------------------------------------
Ran 9 tests in 0.009s

OK

@OmkarPathak OmkarPathak merged commit 75beb5d into OmkarPathak:master Aug 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants