diff --git a/tracks/python/exercises/house/house/mentoring.md b/tracks/python/exercises/house/house/mentoring.md new file mode 100644 index 000000000..c5ba468bc --- /dev/null +++ b/tracks/python/exercises/house/house/mentoring.md @@ -0,0 +1,42 @@ +# Mentoring + +## Reasonable Solutions + +### Solution 1: Straightforward Iteration + +```Python +def recite(start_verse, end_verse): + verses = [] + for i in range(start_verse - 1, end_verse): + clause = " ".join(VERSES[i::-1]) + verses.append(f"This is {clause}") + return verses +``` +#### Explanation: +- Directly starts the loop at start_verse - 1 to avoid unnecessary iterations. +- Uses slicing VERSES[i::-1] to efficiently reverse the order of verses within the clause. + + +### Solution 2: List Comprehension + +```Python +def recite(start_verse, end_verse): + return [f"This is {' '.join(VERSES[i::-1])}" for i in range(start_verse - 1, end_verse)] +``` +#### Explanation: +- Uses list comprehension for a concise way to build the verses list. + +## Common Suggestions +- Optimize the Loop:By starting the loop at start_verse - 1 instead of 0, we can avoid unnecessary iterations and directly jump to the relevant part of the rhyme. +- Slicing: Python's list slicing offers an elegant and efficient way to extract a portion of a list. +- Naming Conventions: Using all capital letters for constants like VERSES is a good practice in Python. +- Error Handling: It's a good practice to add checks for invalid inputs, such as: +``` + start_verse being less than 1 or greater than the length of VERSES + end_verse being less than start_verse or greater than the length of VERSES. +``` + +## Talking Points +- Alternative Approaches: Potential use of recursion. +- The "House that Jack Built" rhyme has a recursive structure. We can use recursion to build the clauses +