-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Added the solution to the new fork #3133
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?
Conversation
mateacademy-ai-mentor
left a comment
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.
Review Summary
I'm approving your solution as it correctly sorts all the variables and meets all the task requirements. Well done! For future reference, you can make your code more efficient and easier to read by avoiding repetition. Instead of writing a separate if/else check for each of the eight variables, consider placing them all in a list. Then, you can use a single for loop to iterate through the list, checking the type of each item and appending it to the appropriate list within sorted_variables. This approach follows the DRY (Don't Repeat Yourself) principle and is a valuable technique to learn. Keep up the great work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| if isinstance(lucky_number, (int, float, bool, str, tuple)): | ||
| immutable.append(lucky_number) | ||
| else: | ||
| mutable.append(lucky_number) | ||
| if isinstance(pi, (int, float, bool, str, tuple)): | ||
| immutable.append(pi) | ||
| else: | ||
| mutable.append(pi) | ||
| if isinstance(one_is_a_prime_number, (int, float, bool, str, tuple)): | ||
| immutable.append(one_is_a_prime_number) | ||
| else: | ||
| mutable.append(one_is_a_prime_number) | ||
| if isinstance(name, (int, float, bool, str, tuple)): | ||
| immutable.append(name) | ||
| else: | ||
| mutable.append(name) | ||
| if isinstance(my_favourite_films, (int, float, bool, str, tuple)): | ||
| immutable.append(my_favourite_films) | ||
| else: | ||
| mutable.append(my_favourite_films) | ||
| if isinstance(profile_info, (int, float, bool, str, tuple)): | ||
| immutable.append(profile_info) | ||
| else: | ||
| mutable.append(profile_info) | ||
| if isinstance(marks, (int, float, bool, str, tuple)): | ||
| immutable.append(marks) | ||
| else: | ||
| mutable.append(marks) | ||
| if isinstance(collection_of_coins, (int, float, bool, str, tuple)): | ||
| immutable.append(collection_of_coins) | ||
| else: | ||
| mutable.append(collection_of_coins) |
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.
This code works, but notice how you're repeating the exact same if/else logic for every single variable. This is a lot of duplicated code. A good practice in programming is to avoid repetition (this is called the DRY principle - Don't Repeat Yourself).
Can you think of a way to use a loop to process all the variables without repeating the isinstance check eight times? Hint: you could put all the variables into a list and then iterate through it.
No description provided.