Skip to content

Commit

Permalink
Create mentoring.md
Browse files Browse the repository at this point in the history
  • Loading branch information
manukirans authored Jun 14, 2024
1 parent 5854d9a commit 286d73f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tracks/python/exercises/house/house/mentoring.md
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 286d73f

Please sign in to comment.