Skip to content

Conversation

@JessieMontaro
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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

  1. Rate AI review example

Comment on lines +20 to +51
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)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants