-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Changes the code To return the list in dynamic_programming/subset_generation.py #10191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes the code To return the list in dynamic_programming/subset_generation.py #10191
Conversation
for more information, see https://pre-commit.ci
Co-authored-by: Christian Clauss <[email protected]>
…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
Co-authored-by: Christian Clauss <[email protected]>
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) = }") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subset_combinations_dp()
should work the same way as itertools.combinations()
. It should present the same sort order and raise the same exceptions.
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) = }") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the code now code giving the list sorted order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for going the extra mile on this one... It is a nice upgrade!
Really challenging and enjoyable. I fix one bug, then two errors comes. It's kind of frustrating, but worth the time. |
Sounds like software engineering to me. ;-) |
…eration.py (TheAlgorithms#10191) * Changing the code to return tuple * Changing the code to return tuple * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update dynamic_programming/subset_generation.py Co-authored-by: Christian Clauss <[email protected]> * Adding doctests in subset_generation.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update subset_generation.py * Update subset_generation.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update subset_generation.py * Update subset_generation.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update dynamic_programming/subset_generation.py Co-authored-by: Christian Clauss <[email protected]> * Update stock_span_problem.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update subset_generation.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update subset_generation.py * Update subset_generation.py * Update subset_generation.py * Update subset_generation.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
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