Skip to content

Commit 5b48c2d

Browse files
authored
Merge branch 'main' into fix-up-wordy-approaches-II
2 parents a342594 + fb1cb44 commit 5b48c2d

File tree

14 files changed

+93
-48
lines changed

14 files changed

+93
-48
lines changed

.github/workflows/ci-workflow.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
housekeeping:
1515
runs-on: ubuntu-22.04
1616
steps:
17-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
17+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
1818

1919
- name: Set up Python
2020
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
@@ -55,7 +55,7 @@ jobs:
5555
matrix:
5656
python-version: [3.7, 3.8, 3.9, 3.10.6, 3.11.2]
5757
steps:
58-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
58+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
5959

6060
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
6161
with:

.github/workflows/issue-commenter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
name: Comments for every NEW issue.
1010
steps:
1111
- name: Checkout
12-
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
12+
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
1313

1414
- name: Read issue-comment.md
1515
id: issue-comment

.github/workflows/test-runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ jobs:
1010
test-runner:
1111
runs-on: ubuntu-22.04
1212
steps:
13-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
13+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
1414
- name: Run test-runner
1515
run: docker compose run test-runner

concepts/list-methods/about.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,22 @@ The order of list elements can be reversed _**in place**_ with `<list>.reverse(
136136
[3, 2, 1]
137137
```
138138

139-
List elements can be sorted _**in place**_ using `<list>.sort()`.
140-
Internally, Python uses [`Timsort`][timsort] to arrange the elements.
141-
The default order is _ascending_.
142-
The Python docs have [additional tips and techniques for sorting][sorting how to] `lists` effectively.
139+
A list can be re-ordered _**in place**_ with the help of [`<list>.sort()`][sort].
140+
Default sort order is _ascending_ from the left.
141+
The Python docs offer [additional tips and techniques for sorting][sorting how to].
142+
143+
144+
~~~~exercism/note
145+
From 2002 to 2022, Python used an algorithm called [`Timsort`][timsort] internally to arrange lists, but switched to [`Powersort`][powersort] from `Python 3.11` onward.
146+
You can read more details and discussion on the change from the core Python team in the GitHub [issue 78742][78742].
147+
148+
For technical details on the algorithm, see the J. Ian Munro and Sebastian Wild paper [Nearly-Optimal Mergesorts: Fast, Practical Sorting Methods That Optimally Adapt to Existing Runs][nearly-optimal-mergesorts]
149+
150+
[78742]: https://github.com/python/cpython/issues/78742
151+
[nearly-optimal-mergesorts]: https://arxiv.org/abs/1805.04154
152+
[powersort]: https://www.wild-inter.net/publications/munro-wild-2018
153+
[timsort]: https://en.wikipedia.org/wiki/Timsort
154+
~~~~
143155

144156

145157
```python
@@ -254,7 +266,7 @@ For a detailed explanation of names, values, list, and nested list behavior, tak
254266
[set]: https://docs.python.org/3/library/stdtypes.html#set
255267
[shallow vs deep]: https://realpython.com/copying-python-objects/
256268
[slice notation]: https://docs.python.org/3/reference/expressions.html#slicings
269+
[sort]: https://docs.python.org/3/library/stdtypes.html#list.sort
257270
[sorted]: https://docs.python.org/3/library/functions.html#sorted
258271
[sorting how to]: https://docs.python.org/3/howto/sorting.html
259-
[timsort]: https://en.wikipedia.org/wiki/Timsort
260272
[tuple]: https://docs.python.org/3/library/stdtypes.html#tuple

concepts/sets/about.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Sets
22

33
A [`set`][type-set] is a _mutable_ and _unordered_ collection of [_hashable_][hashable] objects.
4-
Set members must be distinct -- duplicate items are not allowed.
5-
They can hold multiple different data types and even nested structures like a `tuple` of `tuples` -- as long as all elements can be _hashed_.
4+
Set members must be distinct duplicate items are not allowed.
5+
They can hold multiple different data types and even nested structures like a `tuple` of `tuples` as long as all elements can be _hashed_.
66
Sets also come in an immutable [`frozensets`][type-frozenset] flavor.
77

88
Sets are most commonly used to quickly remove duplicates from other data structures or item groupings.
@@ -360,7 +360,7 @@ The operator version of this method is `<set> - <other set 1> - <other set 2> -
360360
'Goose Berries', 'Strawberries'}
361361

362362
# Operators require sets.
363-
>>> berries_and_veggies - just_berries
363+
>>> berries_and_veggies - berries
364364
{'Artichokes','Asparagus','Broccoli','Kale',
365365
'Ramps','Rhubarb','Walking Onions','Watercress'}
366366
```

concepts/sets/introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Sets
22

33
A [`set`][type-set] is a _mutable_ and _unordered_ collection of [_hashable_][hashable] objects.
4-
Set members must be distinct -- duplicate items are not allowed.
5-
They can hold multiple different data types and even nested structures like a `tuple` of `tuples` -- as long as all elements can be _hashed_.
4+
Set members must be distinct duplicate items are not allowed.
5+
They can hold multiple different data types and even nested structures like a `tuple` of `tuples` as long as all elements can be _hashed_.
66
Sets also come in an immutable [`frozensets`][type-frozenset] flavor.
77

88
Sets are most commonly used to quickly remove duplicates from other data structures or item groupings.

concepts/unpacking-and-multiple-assignment/about.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ ValueError: too many values to unpack (expected 1)
129129

130130
### Unpacking a list/tuple with `*`
131131

132-
When [unpacking a `list`/`tuple`][packing and unpacking] you can use the `*` operator to capture the "leftover" values.
132+
When [unpacking a `list`/`tuple`][packing and unpacking] you can use the `*` operator to capture "leftover" values.
133133
This is clearer than slicing the `list`/`tuple` (_which in some situations is less readable_).
134-
For example, we can extract the first element and then assign the remaining values into a new `list` without the first element:
134+
For example, we can extract the first element and pack the remaining values into a new `list` without the first element:
135135

136136
```python
137137
>>> fruits = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
@@ -169,7 +169,7 @@ We can also use `*` in deep unpacking:
169169

170170
### Unpacking a dictionary
171171

172-
[Unpacking a dictionary][packing and unpacking] is a bit different than unpacking a `list`/`tuple`.
172+
[Unpacking a dictionary][packing and unpacking] is a bit different from unpacking a `list`/`tuple`.
173173
Iteration over dictionaries defaults to the **keys**.
174174
So when unpacking a `dict`, you can only unpack the **keys** and not the **values**:
175175

@@ -180,7 +180,7 @@ So when unpacking a `dict`, you can only unpack the **keys** and not the **value
180180
"apple"
181181
```
182182

183-
If you want to unpack the values then you can use the `values()` method:
183+
If you want to unpack the values then you can use the `<dict>.values()` method:
184184

185185
```python
186186
>>> fruits_inventory = {"apple": 6, "banana": 2, "cherry": 3}
@@ -189,9 +189,9 @@ If you want to unpack the values then you can use the `values()` method:
189189
6
190190
```
191191

192-
If both **keys** and **values** are needed, use the `items()` method.
193-
Using `items()` will generate tuples with **key-value** pairs.
194-
This is because of [`dict.items()` generates an iterable with key-value `tuples`][items].
192+
If both **keys** and **values** are needed, use the [`<dict>.items()`][items] method.
193+
`<dict>.items()` generates an [iterable view][view-objects] containing **key-value** pairs.
194+
These can be unpacked into a `tuple`:
195195

196196
```python
197197
>>> fruits_inventory = {"apple": 6, "banana": 2, "cherry": 3}
@@ -367,8 +367,9 @@ Since `zip()` takes multiple iterables and returns a `list` of `tuples` with the
367367
```
368368

369369
[args and kwargs]: https://www.geeksforgeeks.org/args-kwargs-python/
370-
[items]: https://www.geeksforgeeks.org/python-dictionary-items-method/
370+
[items]: https://docs.python.org/3/library/stdtypes.html#dict.items
371371
[multiple assignment]: https://www.geeksforgeeks.org/assigning-multiple-variables-in-one-line-in-python/
372372
[packing and unpacking]: https://www.geeksforgeeks.org/packing-and-unpacking-arguments-in-python/
373373
[sorting algorithms]: https://realpython.com/sorting-algorithms-python/
374374
[unpacking]: https://www.geeksforgeeks.org/unpacking-arguments-in-python/?ref=rp
375+
[view-objects]: https://docs.python.org/3/library/stdtypes.html#dict-views

exercises/concept/cater-waiter/.docs/instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You and your business partners operate a small catering company. You've just agr
44

55
## 1. Clean up Dish Ingredients
66

7-
The event recipes were added from various sources and their ingredients appear to have duplicate (_or more_) entries -- you don't want to end up purchasing excess items!
7+
The event recipes were added from various sources and their ingredients appear to have duplicate (_or more_) entries you don't want to end up purchasing excess items!
88
Before the shopping and cooking can commence, each dish's ingredient list needs to be "cleaned".
99

1010
Implement the `clean_ingredients(<dish_name>, <dish_ingredients>)` function that takes the name of a dish and a `list` of ingredients.
@@ -138,5 +138,5 @@ from sets_categories_data import example_dishes, EXAMPLE_INTERSECTION
138138

139139
>>> singleton_ingredients(example_dishes, EXAMPLE_INTERSECTION)
140140
...
141-
{'vegetable oil', 'vegetable stock', 'barley malt', 'tofu', 'fresh basil', 'lemon', 'ginger', 'honey', 'spaghetti', 'cornstarch', 'yeast', 'red onion', 'breadcrumbs', 'mixed herbs', 'garlic powder', 'celeriac', 'lemon zest', 'sunflower oil', 'mushrooms', 'silken tofu', 'smoked tofu', 'bell pepper', 'cashews', 'oregano', 'tomatoes', 'parsley', 'red pepper flakes', 'rosemary'}
141+
{'garlic powder', 'sunflower oil', 'mixed herbs', 'cornstarch', 'celeriac', 'honey', 'mushrooms', 'bell pepper', 'rosemary', 'parsley', 'lemon', 'yeast', 'vegetable oil', 'vegetable stock', 'silken tofu', 'tofu', 'cashews', 'lemon zest', 'smoked tofu', 'spaghetti', 'ginger', 'breadcrumbs', 'tomatoes', 'barley malt', 'red pepper flakes', 'oregano', 'red onion', 'fresh basil'}
142142
```

exercises/concept/cater-waiter/.docs/introduction.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Sets
22

3-
A [`set`][type-set] is a _mutable_ and _unordered_ collection of [_hashable_][hashable] objects.
4-
Set members must be distinct -- duplicate items are not allowed.
5-
They can hold multiple different data types and even nested structures like a `tuple` of `tuples` -- as long as all elements can be _hashed_.
3+
4+
A [set][type-set] is a _mutable_ and _unordered_ collection of [_hasable_][hashable] objects.
5+
Set members must be distinct — duplicate items are not allowed.
6+
They can hold multiple different data types and even nested structures like a `tuple` of `tuples` — as long as all elements can be _hashed_.
67
Sets also come in an immutable [`frozensets`][type-frozenset] flavor.
78

89
Sets are most commonly used to quickly remove duplicates from other data structures or item groupings.
@@ -126,6 +127,27 @@ There is no operator equivalent:
126127

127128

128129
```python
130+
# Both mammals and additional_animals are lists.
131+
>>> mammals = ['squirrel','dog','cat','cow', 'tiger', 'elephant']
132+
>>> additional_animals = ['pangolin', 'panda', 'parrot',
133+
'lemur', 'tiger', 'pangolin']
134+
135+
# Animals is a dict.
136+
>>> animals = {'chicken': 'white',
137+
'sparrow': 'grey',
138+
'eagle': 'brown and white',
139+
'albatross': 'grey and white',
140+
'crow': 'black',
141+
'elephant': 'grey',
142+
'dog': 'rust',
143+
'cow': 'black and white',
144+
'tiger': 'orange and black',
145+
'cat': 'grey',
146+
'squirrel': 'black'}
147+
148+
# Birds is a set.
149+
>>> birds = {'crow','sparrow','eagle','chicken', 'albatross'}
150+
129151
# Mammals and birds don't share any elements.
130152
>>> birds.isdisjoint(mammals)
131153
True
@@ -311,7 +333,7 @@ The operator version of this method is `<set> - <other set 1> - <other set 2> -
311333
'Goose Berries', 'Strawberries'}
312334

313335
# Operators require sets.
314-
>>> berries_and_veggies - just_berries
336+
>>> berries_and_veggies - berries
315337
{'Artichokes','Asparagus','Broccoli','Kale',
316338
'Ramps','Rhubarb','Walking Onions','Watercress'}
317339
```

exercises/concept/cater-waiter/sets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def categorize_dish(dish_name, dish_ingredients):
4343
"""Categorize `dish_name` based on `dish_ingredients`.
4444
4545
:param dish_name: str - dish to be categorized.
46-
:param dish_ingredients: list - ingredients for the dish.
46+
:param dish_ingredients: set - ingredients for the dish.
4747
:return: str - the dish name appended with ": <CATEGORY>".
4848
4949
This function should return a string with the `dish name: <CATEGORY>` (which meal category the dish belongs to).

0 commit comments

Comments
 (0)