-
Notifications
You must be signed in to change notification settings - Fork 5
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
Solution for mirror words challenge #38
Solution for mirror words challenge #38
Conversation
Create Solution for mirror words challenge
Hi Aseel, |
Hello, Abdulrahman! |
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.
Overall Feedback:
The function and test files are well-constructed and fulfill many criteria for clear and maintainable code. You have effectively utilized docstrings and tests, and the function successfully passes all provided checks. Nevertheless, there are several areas where enhancements could be made to increase the robustness and user-friendliness of the code:
- Function Naming: The name of the function could be more descriptive to eliminate any ambiguity regarding its purpose. Aligning it with the file name (e.g., mirror_words) may clarify its functionality.
- Type Annotations: Incorporating type annotations for both the input argument and the return value would enhance clarity for readers who may not refer to the docstring.
- Docstring Enhancements: Although your docstring is clear, including information about the treatment of special characters and numbers (as indicated in your tests) along with a high-level overview of the strategy would improve its thoroughness and usefulness for others who may review or extend your code.
- Doctests: Adding a third doctest that illustrates the handling of special characters would further enrich the documentation of the function.
- Code Structure: Enhancing the spacing and organization of the code will contribute to making the implementation more readable and accessible to a wider audience.
- Commented Lines: If the commented-out import statements are unnecessary, consider removing them. If they serve a purpose, please add a clarifying comment to explain their intent.
Overall, excellent work!😇 Implementing these recommendations will raise the quality of your code from great to outstanding.
solutions/mirror_words_challenge.py
Outdated
|
||
Returns: | ||
str: A new string where each word is reversed, but the word order and punctuation | ||
remain unchanged. |
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.
Your docstring very clear and easy to read, I have a small comment here on the return value of the function. You mentioned the type of the return value and you mentioned punctuation. You can also include that numbers and special characters remain unreversed as you mentioned in the test file. This will add more clarity for some just checking the function file.
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.
Thank you for pointing that out! I'll update the return value description to include that numbers and special characters remain unreversed for added clarity.
|
||
>>> reverse_words("Python is fun") | ||
'nohtyP si nuf' | ||
|
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.
The doctests are very clear and shows exactly what the output will be. Consider adding a 3rd doctest and maybe include special characters to show they remain unreversed.
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.
Thank you for the feedback! I'll add a third doctest with special characters to demonstrate how they remain unreversed.
|
||
|
||
def reverse_words(sentence): | ||
""" |
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.
- The function name describes what the function do, but it can be a little confusing since someone might understand it reverses the entire sentence not just the words. I believe it would be better to use the same file name
mirror_words
. It gives a better description of the functions behavior. - Moreover, make sure to include the type annotation, you mentioned in the function docstring the argument and the return value of the function, it would be more clear for someone who just reads the functions name to understand the argument and return value types. The function name would look a lot better like this:
def mirror_words(sentence: str) -> str
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.
Thank you for the feedback! I will rename the function to mirror_words for clarity and update the function signature to include type annotations as suggested.
if not isinstance(sentence, str): | ||
raise TypeError("Input must be a string") | ||
|
||
words = sentence.split() |
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.
Your code is readable, but there is room for improvement in spacing and structure to make it clearer and more organized, so it makes it easier for anyone even those with no experience can read it and understand every stage of the functionality.
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.
Thank you for the suggestion! I will adjust the spacing and structure to make the code more organized and readable for everyone.
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))) | ||
|
||
# from mirror_words_challenge import reverse_words | ||
# from solutions.mirror_words_challenge import reverse_words |
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.
If these lines are unnecessary, delete them. However, if they are intentionally retained for reference or debugging purposes, add a clarifying comment explaining why they are there.
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.
When I push the code, I face an issue where the mirror_words_challenge file cannot be found in the solutions directory. Thank you for the feedback! I'll review these lines to determine if they are necessary. If they are not, I will remove them. If they are intentional for debugging or reference, I will add a comment to clarify their purpose.
""" | ||
Reverses each word in a given sentence while maintaining the order of the words | ||
and correctly handling punctuation marks at the end of words. | ||
|
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.
The docstring is well written and it can be even better with a strategy to make the code even easier to understand for others who might work with or review it in the future.
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.
Thank you for the feedback! I'll enhance the docstring by including an example and a brief note on the function's behavior to make it even clearer for others.
@@ -0,0 +1,86 @@ | |||
# test_mirror_words_challenge |
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.
The file name already shows what file it's, so I think it would be better to remove this comment so the code appears more clean and professional.
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.
Got it, I will delete the comment as suggested. Thank you!
solutions/mirror_words_challenge.py
Outdated
@@ -0,0 +1,44 @@ | |||
# mirror_words_challenge |
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.
The file name already shows what file it's, so I think it would be better to remove this comment so the code appears more clean and professional
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.
Ok, I will remove the comment as you suggested. Thank you for the feedback!
… function's behavior
@abdoalsir |
Lessons Learned from My Mistakes How to Resolve ET CI Check Issues: 1. For py_formatting:
OR: Run the following commands in the terminal:
2. For py_tests
|
Name: Mirror Words Challenge
About: A template PR for code review with a checklist
Behavior
Files
/tests/test_file_name.py
Unit Tests
Function Docstring
Raises:
The Function
Strategy
Do's
Don'ts
Implementation
when it's too restricting.
print
statements anywhere