Commit 955778b
authored
Update two_num.py
### Summary
This commit improves the `twoSum` function by enhancing readability, adhering to Python's PEP 8 guidelines, and improving modularity. The refactored code is now cleaner, easier to maintain, and better suited for future enhancements.
### Changes
- Renamed `twoSum` → `two_sum` to align with PEP 8 naming conventions.
- Improved the docstring to follow PEP 257 standards with clear descriptions, examples, and argument details.
- Replaced the inline `print()` statement with a proper return value, ensuring the function behaves as expected when integrated into larger projects.
- Enhanced variable naming by replacing `compl` with `complement` for improved clarity.
- Added a `main` block for controlled script execution, making the code more modular and easier to test.
- Improved the return logic by explicitly returning `False` when no valid pair is found, ensuring clearer outcomes for edge cases.
### Rationale
These changes prioritize:
- Improved readability for future maintainers.
- Clearer logic to reduce ambiguity in variable names and return behavior.
- Better code structure by separating functional logic from I/O actions.
### Impact
- The function's behavior remains identical for expected use cases.
- Code is now more Pythonic, modular, and maintainable.
- The improved structure sets a stronger foundation for future enhancements, such as unit tests or expanded functionality.1 parent 6469a9c commit 955778b
1 file changed
+27
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
2 | 3 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
| 4 | + | |
| 5 | + | |
7 | 6 | | |
8 | 7 | | |
9 | | - | |
10 | | - | |
11 | | - | |
| 8 | + | |
| 9 | + | |
12 | 10 | | |
13 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | | - | |
| 20 | + | |
| 21 | + | |
17 | 22 | | |
18 | 23 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
0 commit comments