Skip to content

Commit 4b88db8

Browse files
authored
Merge pull request #34 from IanDoarn/master
PEP8 compliance updates and updates to __init__.py files [enhancement]
2 parents 243b632 + 07f8840 commit 4b88db8

File tree

17 files changed

+580
-198
lines changed

17 files changed

+580
-198
lines changed

CONTIRBUTORS.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Contributors:
2+
3+
- Mohamed 'MohamedKiouaz' Kiouaz
4+
- Ashutosh 'ashu01' Gupta
5+
- Allston 'AllstonMickey' Mickey
6+
- Dmytro 'dmytrostriletskyi' Striletskyi
7+
- Emett 'the-kid89' Speer
8+
- Viktor 'vhag' Hagstrom
9+
- Dion 'kingdion' Misic
10+
- Chandan 'crowchirp' Rai
11+
- Jae Hyeon 'skystar-p' Park
12+
- dstark85
13+
- Songzhuozhuo 'souo'
14+
- Emil 'Skeen' Madsen

pygorithm/__init__.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
Pygorithm
3+
4+
A Python module to learn all the major algorithms on the go!
5+
Purely for educational purposes
6+
7+
If you have found my software to be of any use to you,
8+
do consider helping me pay my internet bills.
9+
This would encourage me to create many such softwares :)
10+
11+
PayPal -> https://paypal.me/omkarpathak27
12+
INR - > https://www.instamojo.com/@omkarpathak/
13+
14+
CONTRIBUTORS:
15+
16+
Mohamed 'MohamedKiouaz' Kiouaz
17+
Ashutosh 'ashu01' Gupta
18+
Allston 'AllstonMickey' Mickey
19+
Dmytro 'dmytrostriletskyi' Striletskyi
20+
Emett 'the-kid89' Speer
21+
Viktor 'vhag' Hagstrom
22+
Dion 'kingdion' Misic
23+
Chandan 'crowchirp' Rai
24+
Jae Hyeon 'skystar-p' Park
25+
dstark85
26+
Songzhuozhuo 'souo'
27+
Emil 'Skeen' Madsen
28+
29+
"""
30+
from pygorithm import data_structures
31+
from pygorithm import fibonacci
32+
from pygorithm import math
33+
from pygorithm import searching
34+
from pygorithm import sorting
35+
36+
__version__ = '1.0.0'
37+
__author__ = 'Omkar Pathak'
38+
39+
# List maintainers here
40+
__maintainers__ = [
41+
'Omkar Pathak'
42+
]
43+
# List contributors here
44+
__contributors__ = [
45+
"Omkar 'OmkarPathak' Pathak"
46+
"Mohamed 'MohamedKiouaz' Kiouaz",
47+
"Ashutosh 'ashu01' Gupta",
48+
"Allston 'AllstonMickey' Mickey",
49+
"Dmytro 'dmytrostriletskyi' Striletskyi",
50+
"Emett 'the-kid89' Speer",
51+
"Viktor 'vhag' Hagstrom",
52+
"Dion 'kingdion' Misic",
53+
"Chandan 'crowchirp' Rai",
54+
"Jae Hyeon 'skystar-p' Park",
55+
"dstark85",
56+
"Songzhuozhuo 'souo'",
57+
"Emil 'Skeen' Madsen"
58+
]
59+
60+
__all__ = [
61+
'data_structures',
62+
'fibonacci',
63+
'math',
64+
'searching',
65+
'sorting'
66+
]

pygorithm/data_structures/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
from . modules import modules
1+
from . import graph
2+
from . import heap
3+
from . import linked_list
4+
from . import queue
5+
from . import stack
6+
from . import tree
7+
8+
__all__ = [
9+
'graph',
10+
'heap',
11+
'linked_list',
12+
'queue',
13+
'stack',
14+
'tree'
15+
]

pygorithm/fibonacci/__init__.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
from pygorithm.fibonacci import generator
2-
from pygorithm.fibonacci import goldenratio
3-
from pygorithm.fibonacci import memoization
4-
from pygorithm.fibonacci.modules import modules
5-
from pygorithm.fibonacci import recursion
1+
"""
2+
Collection of fibonacci methods and functions
3+
"""
4+
from . import generator
5+
from . import goldenratio
6+
from . import memoization
7+
from . import modules
8+
from . import recursion
9+
10+
__all__ = [
11+
'generator',
12+
'goldenratio',
13+
'memoization',
14+
'recursion'
15+
]

pygorithm/math/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
from . modules import modules
1+
"""
2+
Collection of special math functions
3+
"""
4+
from . import lcm
5+
from . import lcm_using_gcd
6+
from . import sieve_of_eratosthenes
7+
8+
__all__ = [
9+
'lcm',
10+
'lcm_using_gcd',
11+
'sieve_of_eratosthenes'
12+
]

pygorithm/searching/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
from . modules import modules
1+
"""
2+
Collection of searching algorithms
3+
"""
4+
from . import binary_search
5+
from . import breadth_first_search
6+
from . import depth_first_search
7+
from . import linear_search
8+
from . import quick_select
9+
10+
__all__ = [
11+
'binary_search',
12+
'breadth_first_search',
13+
'depth_first_search',
14+
'linear_search',
15+
'quick_select'
16+
]

pygorithm/sorting/__init__.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
from . modules import modules
1+
"""
2+
Collection of sorting methods
3+
"""
4+
from . import quick_sort
5+
from . import bucket_sort
6+
from . import bubble_sort
7+
from . import heap_sort
8+
from . import counting_sort
9+
from . import insertion_sort
10+
from . import merge_sort
11+
from . import selection_sort
12+
from . import shell_sort
13+
14+
__all__ = [
15+
'bubble_sort',
16+
'bucket_sort',
17+
'counting_sort',
18+
'heap_sort',
19+
'insertion_sort',
20+
'merge_sort',
21+
'quick_sort',
22+
'selection_sort',
23+
'shell_sort'
24+
]

pygorithm/sorting/bubble_sort.py

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,63 @@
1-
# Author: OMKAR PATHAK
2-
# Contributors: Mohamed Kiouaz
3-
# Created On: 31st July 2017
4-
5-
# Best O(n); Average O(n*(n-1)/4); Worst O(n^2)
6-
7-
# Bubble Sorting algorithm
8-
def sort(List):
9-
for i in range(len(List)):
10-
for j in range(len(List) - 1, i, -1):
11-
if List[j] < List[j - 1]:
12-
List[j], List[j - 1] = List[j - 1], List[j]
13-
return List
14-
15-
# Improved Bubble Sorting algorithm
16-
def improved_sort(List):
17-
for i in range(len(List)):
1+
"""
2+
Author: OMKAR PATHAK
3+
Contributors: Mohamed Kiouaz
4+
Created On: 31st July 2017
5+
6+
Best O(n); Average O(n*(n-1)/4); Worst O(n^2)
7+
"""
8+
import inspect
9+
10+
11+
def sort(_list):
12+
"""
13+
Bubble Sorting algorithm
14+
15+
:param _list: list of values to sort
16+
:return: sorted values
17+
"""
18+
for i in range(len(_list)):
19+
for j in range(len(_list) - 1, i, -1):
20+
if _list[j] < _list[j - 1]:
21+
_list[j], _list[j - 1] = _list[j - 1], _list[j]
22+
return _list
23+
24+
25+
def improved_sort(_list):
26+
"""
27+
Improved Bubble Sorting algorithm
28+
29+
:param _list: list of values to sort
30+
:return: sorted values
31+
"""
32+
for i in range(len(_list)):
1833
stop = True
19-
for j in range(len(List) - 1, i, -1):
20-
if List[j] < List[j - 1]:
34+
for j in range(len(_list) - 1, i, -1):
35+
if _list[j] < _list[j - 1]:
2136
stop = False
22-
List[j], List[j - 1] = List[j - 1], List[j]
23-
if(stop == True):
24-
return List
25-
return List
37+
_list[j], _list[j - 1] = _list[j - 1], _list[j]
38+
if stop:
39+
return _list
40+
return _list
41+
2642

27-
# time complexities
43+
# TODO: Are these necessary?
2844
def time_complexities():
29-
return '''Best Case: O(n) , Average Case: O(n ^ 2), Worst Case: O(n ^ 2) \n For Improved Bubble Sort: \n Best Case: O(n); Average Case: O(n * (n - 1) / 4); Worst Case: O(n ^ 2) '''
45+
"""
46+
Return information on functions
47+
time complexity
48+
:return: string
49+
"""
50+
return "Best Case: O(n), " \
51+
"Average Case: O(n ^ 2), " \
52+
"Worst Case: O(n ^ 2).\n\n" \
53+
"For Improved Bubble Sort:\nBest Case: O(n); Average Case: O(n * (n - 1) / 4); Worst Case: O(n ^ 2)"
54+
3055

31-
# easily retrieve the source code of the sort function
3256
def get_code():
33-
import inspect
34-
return inspect.getsource(sort)
57+
"""
58+
easily retrieve the source code
59+
of the sort function
3560
36-
# easily retrieve the source code of the sort function
37-
def get_improved_code():
38-
import inspect
39-
return inspect.getsource(improved_sort)
61+
:return: source code
62+
"""
63+
return inspect.getsource(sort)

pygorithm/sorting/bucket_sort.py

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,83 @@
1-
# Author: OMKAR PATHAK
2-
# Created On: 31st July 2017
1+
"""
2+
Author: OMKAR PATHAK
3+
Created On: 31st July 2017
34
4-
# Best O(n); Average O(n); Worst O(n)
5+
- Best O(n)
6+
- Average O(n)
7+
- Worst O(n)
8+
"""
9+
import math
10+
from pygorithm.sorting import insertion_sort
11+
import inspect
512

6-
# bucket sort algorithm
7-
def sort(List, bucketSize = 5):
8-
from pygorithm.sorting import insertion_sort
9-
import math
1013

14+
def sort(_list, bucket_size=5):
15+
"""
16+
bucket sort algorithm
17+
18+
:param _list: list of values to sort
19+
:param bucket_size: Size of the bucket
20+
:return: sorted values
21+
"""
1122
string = False
1223

13-
if(len(List) == 0):
14-
print('You don\'t have any elements in array!')
15-
elif all(isinstance(element, str) for element in List):
24+
if len(_list) == 0:
25+
# print("You don\'t have any elements in array!")
26+
raise ValueError("Array can not be empty.")
27+
28+
elif all(isinstance(element, str) for element in _list):
1629
string = True
17-
List = [ord(element) for element in List]
30+
_list = [ord(element) for element in _list]
1831

19-
minValue = List[0]
20-
maxValue = List[0]
32+
min_value = _list[0]
33+
max_value = _list[0]
2134

2235
# For finding minimum and maximum values
23-
for i in range(0, len(List)):
24-
if List[i] < minValue:
25-
minValue = List[i]
26-
elif List[i] > maxValue:
27-
maxValue = List[i]
36+
for i in range(0, len(_list)):
37+
if _list[i] < min_value:
38+
min_value = _list[i]
39+
elif _list[i] > max_value:
40+
max_value = _list[i]
2841

2942
# Initialize buckets
30-
bucketCount = math.floor((maxValue - minValue) / bucketSize) + 1
43+
bucket_count = math.floor((max_value - min_value) / bucket_size) + 1
3144
buckets = []
32-
for i in range(0, bucketCount):
45+
for i in range(0, int(bucket_count)):
3346
buckets.append([])
3447

3548
# For putting values in buckets
36-
for i in range(0, len(List)):
37-
buckets[math.floor((List[i] - minValue) / bucketSize)].append(List[i])
49+
for i in range(0, len(_list)):
50+
# TODO: floor expects floats but could be receiving int or slice
51+
buckets[math.floor(float((_list[i] - min_value) / bucket_size))].append(_list[i])
3852

3953
# Sort buckets and place back into input array
40-
sortedArray = []
54+
sorted_array = []
4155
for i in range(0, len(buckets)):
4256
insertion_sort.sort(buckets[i])
4357
for j in range(0, len(buckets[i])):
44-
sortedArray.append(buckets[i][j])
58+
sorted_array.append(buckets[i][j])
4559

4660
if string:
47-
return [chr(element) for element in sortedArray]
61+
return [chr(element) for element in sorted_array]
4862
else:
49-
return sortedArray
63+
return sorted_array
5064

51-
# time complexities
65+
66+
# TODO: Are these necessary?
5267
def time_complexities():
53-
return '''Best Case: O(n), Average Case: O(n), Worst Case: O(n)'''
68+
"""
69+
Return information on functions
70+
time complexity
71+
:return: string
72+
"""
73+
return "Best Case: O(n), Average Case: O(n), Worst Case: O(n)"
74+
5475

55-
# easily retrieve the source code of the sort function
5676
def get_code():
57-
import inspect
77+
"""
78+
easily retrieve the source code
79+
of the sort function
80+
81+
:return: source code
82+
"""
5883
return inspect.getsource(sort)

0 commit comments

Comments
 (0)