Skip to content

Commit f97b3a2

Browse files
authored
Revised function call.
Moved __get_num_digits() function call into the radix() function, so the only parameter when calling radix() is a List.
1 parent fb4b0c8 commit f97b3a2

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Sorting Algorithms/Radix_Sort.ipynb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
{
1212
"cell_type": "code",
13-
"execution_count": 5,
13+
"execution_count": 1,
1414
"metadata": {},
1515
"outputs": [],
1616
"source": [
@@ -24,7 +24,7 @@
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": 6,
27+
"execution_count": 2,
2828
"metadata": {},
2929
"outputs": [],
3030
"source": [
@@ -34,13 +34,22 @@
3434
" return reduce(lambda x, y: x + y, A)"
3535
]
3636
},
37+
{
38+
"cell_type": "markdown",
39+
"metadata": {},
40+
"source": [
41+
"### Changed from YouTube video:\n",
42+
"It's much cleaner to put the _get_num_digits call inside the radix function rather than in main as shown in the video. That way you only need to pass a List to the radix function. Thanks to Brother Lui for this suggestion."
43+
]
44+
},
3745
{
3846
"cell_type": "code",
39-
"execution_count": 7,
47+
"execution_count": 3,
4048
"metadata": {},
4149
"outputs": [],
4250
"source": [
43-
"def radix(A, num_digits):\n",
51+
"def radix(A):\n",
52+
" num_digits = __get_num_digits(A)\n",
4453
" for digit in range(0, num_digits):\n",
4554
" B = [[] for i in range(10)]\n",
4655
" for item in A:\n",
@@ -53,7 +62,7 @@
5362
},
5463
{
5564
"cell_type": "code",
56-
"execution_count": 9,
65+
"execution_count": 4,
5766
"metadata": {},
5867
"outputs": [
5968
{
@@ -68,14 +77,13 @@
6877
"source": [
6978
"def main():\n",
7079
" A = [55, 45, 3, 289, 213, 1, 288, 53, 2]\n",
71-
" num_digits = __get_num_digits(A)\n",
72-
" A = radix(A, num_digits)\n",
80+
" A = radix(A)\n",
7381
" print(A)\n",
7482
" \n",
7583
" B = [i for i in range(1000000)]\n",
7684
" from random import shuffle\n",
7785
" shuffle(B)\n",
78-
" B = radix(B, __get_num_digits(B))\n",
86+
" B = radix(B)\n",
7987
" print(B[:6], B[-6:])\n",
8088
"\n",
8189
"main()"

0 commit comments

Comments
 (0)