From 286d73f593e3b2f825ad97f8a682a863296ddc9e Mon Sep 17 00:00:00 2001 From: Manu Kiran S <143595414+manukirans@users.noreply.github.com> Date: Fri, 14 Jun 2024 23:24:08 +0530 Subject: [PATCH 1/2] Create mentoring.md --- .../python/exercises/house/house/mentoring.md | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tracks/python/exercises/house/house/mentoring.md 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 + From 25ec4e7c9460ad297ac975d45dd8077367adea15 Mon Sep 17 00:00:00 2001 From: Manu Kiran S <143595414+manukirans@users.noreply.github.com> Date: Mon, 17 Jun 2024 20:29:01 +0530 Subject: [PATCH 2/2] Delete tracks/python/exercises/house/house/mentoring.md --- .../python/exercises/house/house/mentoring.md | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 tracks/python/exercises/house/house/mentoring.md diff --git a/tracks/python/exercises/house/house/mentoring.md b/tracks/python/exercises/house/house/mentoring.md deleted file mode 100644 index c5ba468bc..000000000 --- a/tracks/python/exercises/house/house/mentoring.md +++ /dev/null @@ -1,42 +0,0 @@ -# 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 -