-
-
Notifications
You must be signed in to change notification settings - Fork 49.6k
Closed
Labels
staleUsed to mark an issue or pull request stale.Used to mark an issue or pull request stale.
Description
The strand_sort function takes in a parameter solution with a default value None, and the default case represents merging arr after sorting with the empty list []. Passing in a falsy value to solution like 0 or False should raise an error since we cannot merge the sorted list with such falsy values, but with the current implementation, we still assign [] to solution on line 21 due to falsy values and the function continues without errors.
File path: https://github.com/TheAlgorithms/Python/blob/master/sorts/strand_sort.py
def strand_sort(arr: list, reverse: bool = False, solution: list = None) -> list:
--
5 | """
6 | Strand sort implementation
7 | source: https://en.wikipedia.org/wiki/Strand_sort
8 |
9 | :param arr: Unordered input list
10 | :param reverse: Descent ordering flag
11 | :param solution: Ordered items container
12 |
13 | Examples:
14 | >>> strand_sort([4, 2, 5, 3, 0, 1])
15 | [0, 1, 2, 3, 4, 5]
16 |
17 | >>> strand_sort([4, 2, 5, 3, 0, 1], reverse=True)
18 | [5, 4, 3, 2, 1, 0]
19 | """
20 | _operator = operator.lt if reverse else operator.gt
21 | solution = solution or []
Metadata
Metadata
Assignees
Labels
staleUsed to mark an issue or pull request stale.Used to mark an issue or pull request stale.