Changes the code To return the list in dynamic_programming/subset_generation.py#10191
Merged
cclauss merged 27 commits intoTheAlgorithms:masterfrom Oct 15, 2023
Merged
Conversation
for more information, see https://pre-commit.ci
cclauss
reviewed
Oct 15, 2023
cclauss
reviewed
Oct 15, 2023
Co-authored-by: Christian Clauss <cclauss@me.com>
…xingIssuereturntupple # Conflicts: # dynamic_programming/subset_generation.py
for more information, see https://pre-commit.ci
…xingIssuereturntupple # Conflicts: # dynamic_programming/subset_generation.py
for more information, see https://pre-commit.ci
…xingIssuereturntupple
for more information, see https://pre-commit.ci
cclauss
reviewed
Oct 15, 2023
Co-authored-by: Christian Clauss <cclauss@me.com>
cclauss
reviewed
Oct 15, 2023
| arr = [10, 20, 30, 40, 50] | ||
| print_combination(arr, len(arr), 3) | ||
| # This code is contributed by Ambuj sahu | ||
| print(f"{subset_combinations_dp(elements=[10, 20, 30, 40], n=2) = }") |
Member
There was a problem hiding this comment.
subset_combinations_dp() should work the same way as itertools.combinations(). It should present the same sort order and raise the same exceptions.
Suggested change
| print(f"{subset_combinations_dp(elements=[10, 20, 30, 40], n=2) = }") | |
| from itertools import combinations | |
| for items, n in ( | |
| ([10, 20, 30, 40], 2), ([1, 2, 3], 1), ([1, 2, 3], 3), ([42], 1), | |
| ([6, 7, 8, 9], 4), ([10, 20, 30, 40, 50], 1), ([1, 2, 3, 4], 2), | |
| ([1, 'apple', 3.14], 2), (['single'], 0), ([], 9) | |
| ): | |
| actual = subset_combinations_dp(items, n) | |
| expected = list(combinations(items, n)) | |
| assert actual == expected, f"items, n: {actual} != {expected}" | |
| print(f"{subset_combinations_dp(elements=[10, 20, 30, 40], n=2) = }") |
Contributor
Author
There was a problem hiding this comment.
I have changed the code now code giving the list sorted order
Member
There was a problem hiding this comment.
itertools.combinations([1, 'apple', 3.14], 2)
…xingIssuereturntupple
for more information, see https://pre-commit.ci
…xingIssuereturntupple
for more information, see https://pre-commit.ci
…xingIssuereturntupple
cclauss
approved these changes
Oct 15, 2023
Member
cclauss
left a comment
There was a problem hiding this comment.
Thanks for going the extra mile on this one... It is a nice upgrade!
Contributor
Author
|
Really challenging and enjoyable. I fix one bug, then two errors comes. It's kind of frustrating, but worth the time. |
Member
Sounds like software engineering to me. ;-) |
14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
Changes the code to return the tuples. So, we can add doctests in it after it. Change the whole code now code using dynamic programming as it header says
Checklist:
Change Code to return tuple in dynamic_programming/subset_generation.py #10189