-
-
Notifications
You must be signed in to change notification settings - Fork 50.5k
fix: the all_permutations in all_permutations.py #14595
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,7 +78,11 @@ def create_state_space_tree( | |
| remove the comment to take an input from the user | ||
| print("Enter the elements") | ||
| sequence = list(map(int, input().split())) | ||
| MAX_SEQUENCE_LENGTH = 8 | ||
| user_input = list(map(int, input().split())) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still only supports integer input from the user, while the function type hints allow both |
||
| if len(user_input) > MAX_SEQUENCE_LENGTH: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The length check happens after converting all input values into a list. For very large input, this still loads everything into memory first. Consider checking the split input length before mapping to integers. |
||
| raise ValueError(f"Input sequence too long (max {MAX_SEQUENCE_LENGTH} elements).") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a test or doctest for the new length limit so this behavior is verified automatically and does not regress later. |
||
| sequence = user_input | ||
| """ | ||
|
|
||
| sequence: list[int | str] = [3, 1, 2, 4] | ||
|
|
||
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.
Consider moving
MAX_SEQUENCE_LENGTHto the module level instead of defining it inside this input block. That makes the limit easier to find, reuse, and update later.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.
@orbisai0security can you address code review comments?