-
-
Notifications
You must be signed in to change notification settings - Fork 957
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
Changes from all commits
990a3a5
0f4b246
64fd6c4
16fe8ba
8ec5b31
202947e
06601ca
9fc01aa
9475574
56aca90
2ea04ec
fe12914
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functions should be separated by two blank lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mentors should be familiar with There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`. | ||
|
||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.