Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded strand sort #1982
Added strand sort #1982
Conversation
| import operator | ||
|
|
||
|
|
||
| def strand_sort(arr: list, solution: list, _operator: callable): |
This comment has been minimized.
This comment has been minimized.
cclauss
May 14, 2020
Member
This sort would be easier to use (and test) if it returned a list instead of requiring the caller to allocate and pass in a solution list. It would also be cool if strand_sort() was defined to work like the Python builtin sorted() which has an optional reverse parameter that defaults to False. We don't need to support the key parameter of sorted() but the reverse would make a lot of sense.
This comment has been minimized.
This comment has been minimized.
mateuszz0000
May 14, 2020
Author
Contributor
I am agreed. One question because this implementation needs recursive passing solution array because algorithm depends on deleting items from input source. Should I avoid recursion?
This comment has been minimized.
This comment has been minimized.
cclauss
May 14, 2020
•
Member
def strand_sort(arr: list, reverse: bool=False, solution: list=None):
solution = solution or []
your code goes here...This will allow the caller to just pass in the arr to be sorted but also allows the function to call itself recursively. Best of both worlds.
| strand_asc = partial(strand_sort, _operator=operator.gt) | ||
| strand_desc = partial(strand_sort, _operator=operator.lt) |
This comment has been minimized.
This comment has been minimized.
cclauss
May 14, 2020
Member
I'm not a fan. Let's lose partial and define strand_sort() to work like the Python builtin sorted() which has an optional reverse parameter that defaults to False.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cclauss
May 14, 2020
Member
Partial has its place. I tend to use it rarely. The real point is that sort algorithms in Python should try to have similar calling conventions to the builtin sorted() so developers find them intuitive (Pythonic) to use.
mateuszz0000 commentedMay 14, 2020
Describe your change:
I didn't find strand sort (https://en.wikipedia.org/wiki/Strand_sort) implemenation so here it is.
Checklist:
Fixes: #{$ISSUE_NO}.