Skip to content

Added the mentoring.md file to Pig Latin exercise #2343

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

Closed
wants to merge 12 commits into from
4 changes: 2 additions & 2 deletions tracks/python/exercises/armstrong-numbers/mentoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def is_armstrong_number(number):
# With a generator expression passed to sum
total = sum(digit ** count for digit in digits)
```
Students are often unaware of [generator expressions][pep-289] and that they can be passed directly to functions that accept iterables.
The first line uses a comprehension to build a `list` for `sum()` to iterate through.
Students are often unaware of [generator expressions][pep-289] and that they can be passed directly to functions that accept iteration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentionally part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry about that. I committed to the main branch. it was a mistake.

The first line uses comprehension to build a `list` for `sum()` to iterate through.
The middle step of a temporary list takes up space in memory and is not needed.
The second line shows the `list` replaced by an equivalent `generator expression` that `sum()` can also iterate through.

Expand Down
6 changes: 3 additions & 3 deletions tracks/python/exercises/perfect-numbers/mentoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A simple optimization is to use `range(1, number // 2 + 1)` as the `for` loop `i
This halves the complexity of the solution.

For a more efficient solution, one can compute all the factors by using the smaller `range(1, int(math.sqrt(number)) + 1)` as the `iterable`.
This solution is longer and more involved but significantly faster, reducing the complextiy from `O(n)` (_linear_) to `O(sqrt(n))` (_square root_).
This solution is longer and more involved but significantly faster, reducing the complexity from `O(n)` (_linear_) to `O(sqrt(n))` (_square root_).

```python
def classify(number):
Expand All @@ -49,5 +49,5 @@ def classify(number):

Students unfamiliar with `generator expressions` might write: `aliquot = sum([item for item in range(1, number) if number % item == 0])`.
Note this first creates a `list` of factors in memory by iterating over the entire range, then iterates once more over the `list` to `sum()` its values.
This is inefficent for both memory and processing time.
Dropping the `[]` drops `list` creation and allows `sum()` to lazily process a `generator expression`, wich only requires a single iteration and a smaller memory footprint.
This is inefficient for both memory and processing time.
Dropping the `[]` drops `list` creation and allows `sum()` to lazily process a `generator expression`, which only requires a single iteration and a smaller memory footprint.
87 changes: 87 additions & 0 deletions tracks/python/exercises/pig-latin/pig-latin/mentoring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Mentoring

## Problem and challenges

The problem requires the student to rearrange the English word based on the given rules in the instruction.

## Reasonable solutions

This exercise can be solved by using one `for` loop.

```
def translate(text):
return ' '.join([pig(word) for word in text.split(' ')])
def pig(word):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions should be separated by two blank lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay.

if word[0] not in 'aieou' and word[1:3] == 'qu':
return word[3:] + word[:3] + "ay"
if word[0] in 'aieou':
return word + "ay"
if word[:2] in ['yt', 'xr']:
return word + "ay"
if word[:2] in ['qu']:
return word[2:] + word[:2] + "ay"
if set('aieou') - set(word) == set('aieou') and 'yt' not in word:
return word[1:] + word[:1] + "ay"
return pig(word[1:] + word[0])
```

Exercise solved using two `for` loops.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally mentoring notes have a single reasonable solution. Is there something significant about the second solution that warrants two solutions? The number of for statements isn't very descriptive of what's special about the second solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I will remove the 2nd solution.


```
def translate(sentence):
words = sentence.split()
pig_latin_words = [translate_to_pig_latin(word) for word in words]
return ' '.join(pig_latin_words)


def translate_to_pig_latin(word):
vowels = "aeiou"

# Rule 1: Word begins with a vowel or starts with "xr" or "yt"
if word[0] in vowels or word.startswith("xr") or word.startswith("yt"):
return word + "ay"

# Rule 3 and Rule 4 need to be checked within the loop
for i, char in enumerate(word):
if char == "u" and i > 0 and word[i-1] == 'q':
# Rule 3: "qu" handling
return word[i + 1:] + word[:i + 1] + "ay"
elif char in vowels:
# Rule 2: Move initial consonants to the end and add "ay"
return word[i:] + word[:i] + "ay"
elif char == 'y' and i > 0:
# Rule 4: Consonants followed by "y"
return word[i:] + word[:i] + "ay"

# If no vowels are found, just add "ay" to the word (edge case)
return word + "ay"
```

Prefer to use the first approach. Using multiple `for` loops in your code can sometimes lead to readability issues and inefficiencies. Remember that readability and maintainability are crucial.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exercism markdown should have one sentence per line.

Mentoring notes shouldn't be telling mentors what solution students should use. There are a lot of approaches which are valid. There is no one correct approach.

Are there common talking points you've returned to when mentoring this exercise? That's what mentoring notes should contain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.


## Talking points

1. Students may unfamiliar with `join()` may use `for` loop or list comprehension to concatenate:

```
my_list = ["apple", "banana", "cherry"]
separator = ", "
result = separator.join(my_list)
print(result)
# Output: "apple, banana, cherry"
```

2. Also students may unfamiliar with `set()`:

The `set()` function is a powerful data structure in Python.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentors should be familiar with set. There is no need to explain what set() is to mentors. This point says "consider set" but doesn't explain why set is useful here or how it helps solve this exercise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will be adding that


- A set is an unordered collection of unique elements.
- You can create a set using curly braces {} or the set() constructor.

Example:
```
my_set = {1, 2, 3, 4}
```
suggest students to look at the basic operations on `set`.


Loading