Skip to content

Commit ed1ae6c

Browse files
author
Brett
committed
small changes to readme.md tables/headers.
sorter.py version updated and comment fixes.
1 parent bca31c1 commit ed1ae6c

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ Check the [releases](https://github.com/becurrie/sorters-py/releases) section to
1919

2020
#### Arguments
2121

22-
| Argument | Description | Example |
23-
|-----------------|------------------------------------------------------------|------------------------------------|
24-
| -s / --sort | type of sort being performed on list | ```python -m sorter -s radix``` |
25-
| -i / --integers | provide a list of integers to be sorted | ```python -m sorter -i 9 34 5 4``` |
26-
| -g / --generate | generate a random list of integers to be sorted | ```python -m sorter -g 1000``` |
27-
| -l / --list | displays the original/sorted lists | ```python -m sorter -l``` |
28-
| -a / --allsorts | perform sort on list with each algorithm, except bogo sort | ```python -m sorter -a``` |
22+
| Argument | Description | Example |
23+
|-----------------|------------------------------------------------------------|---------------------------------------|
24+
| -s / --sort | type of sort being performed on list | ```python -m py_sorter -s radix``` |
25+
| -i / --integers | provide a list of integers to be sorted | ```python -m py_sorter -i 9 34 5 4``` |
26+
| -g / --generate | generate a random list of integers to be sorted | ```python -m py_sorter -g 1000``` |
27+
| -l / --list | displays the original/sorted lists | ```python -m py_sorter -l``` |
28+
| -a / --allsorts | perform sort on list with each algorithm, except bogo sort | ```python -m py_sorter -a``` |
2929

3030
## Examples
3131

@@ -68,7 +68,7 @@ an array and checks it's been sorted, shuffling infinitely until list is sorted.
6868

6969
- Clone repository locally.
7070
- ```python setup.py install```.
71-
- Access module from console with ```python -m py_sorter```.
71+
- Access module from console with ```python -m py_sorter [args]```.
7272

7373
## Development
7474

py_sorter/sorter.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""py_sorter.sorter: provides argument parsing and entry point main()."""
22

3-
__version__ = "0.2.0"
3+
__version__ = "0.2.1"
44

55

66
import argparse
77
import os
8-
import sys
98
import timeit
109

1110
from random import randint
@@ -69,13 +68,16 @@ def print_results(args, sorted_list, time):
6968

7069

7170
def print_list_chunks(integer_list, n):
72-
"""Simple helper method to print out a list in chunks."""
71+
"""Simple helper method to print out a list in chunks. This allows
72+
the console output to never surpass a specific width. Giving a cleaner
73+
output if the original/sorted lists are being printed.
74+
"""
7375
for i in range(0, len(integer_list), n):
7476
yield integer_list[i:i + n]
7577

7678

7779
def generate_integer_list(size):
78-
"""Generate a list of Integers between specified size value."""
80+
"""Generate a list of integers between specified size value."""
7981
integer_list = list()
8082
for i in range(0, size):
8183
integer_list.append(randint(0, 1000))
@@ -87,48 +89,42 @@ def sort(args):
8789
"""Sort a list of integers based on the type of sort specified. Any recursive
8890
algorithms use a try/except to print an error if recursive depth is reached.
8991
"""
90-
# Create empty sorted_list variable.
92+
# Create a clone of the initial args.integers property.
9193
original_list = list(args.integers)
94+
95+
# Empty sorted_list that will hold list after sort method returns.
9296
sorted_list = list()
9397

9498
# Initial default_timer() method call to grab current time of call.
9599
initial = timeit.default_timer()
96100
if args.sort == 'bubble':
97101
sorted_list = bubble_sort(original_list)
98-
99102
elif args.sort == 'bogo':
100103
sorted_list = bogo_sort(original_list)
101-
102104
elif args.sort == 'selection':
103105
sorted_list = selection_sort(original_list)
104-
105106
elif args.sort == 'merge':
106107
sorted_list = merge_sort(original_list)
107-
108108
elif args.sort == 'quick':
109109
try:
110110
sorted_list = quick_sort(original_list)
111111
except RecursionError as e:
112112
print_error(args, e.args[0])
113113
return
114-
115114
elif args.sort == 'radix':
116115
try:
117116
sorted_list = radix_sort(original_list)
118117
except RecursionError as e:
119118
print_error(args, e.args[0])
120119
return
121-
122120
elif args.sort == 'insertion':
123121
sorted_list = insertion_sort(original_list)
124-
125122
elif args.sort == 'insertion_recursive':
126123
try:
127124
sorted_list = insertion_sort_recursive(original_list)
128125
except RecursionError as e:
129126
print_error(args, e.args[0])
130127
return
131-
132128
elif args.sort == 'heap':
133129
sorted_list = heap_sort(original_list)
134130

0 commit comments

Comments
 (0)