Skip to content

Commit ebf906e

Browse files
Adam LevinSleeplessByte
authored andcommitted
Clarify mutation is allowed in high-scores (#1195)
* Clarify mutation is allowed in high-scores Adding a test to check against mutating the list has been suggested and rejected because this is an introductory core exercise and immutability has not yet been introduced. However, all of the reasonable examples provided do not mutate the list so it is not clear to new mentors whether preserving the original list is required when deciding if they should accept a solution. * Provided examples of solutions that mutate
1 parent 6f6e3ff commit ebf906e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tracks/python/exercises/high-scores/mentoring.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ Another variation of this solution includes the start at -1 for slicing the resu
4848
return sorted(scores)[-1:-4:-1]
4949
```
5050

51+
Since immutability has not yet been introduced, solutions that mutate the original list (`scores.pop()` or `scores.sort()`) are acceptable. However, take the opportunity to start introducing this concept in your comments.
52+
```python
53+
def latest(scores):
54+
return scores.pop()
55+
56+
def personal_top_three(scores):
57+
scores.sort(reverse=True)
58+
return scores[:3]
59+
```
60+
5161
### Common Suggestions
5262

5363
- Use **`sorted()`** over **`sort()`**. `sorted()` returns a _**copy**_ , `sort()` _**mutates in place**_.

0 commit comments

Comments
 (0)