From 75781a414960b0204b5456a6a9d03ff8b6c128ea Mon Sep 17 00:00:00 2001 From: BethanyG Date: Wed, 13 May 2026 14:17:32 -0700 Subject: [PATCH 1/2] Typo and formatting fixes as outlined on https://forum.exercism.org/t/mecha-munch-management-typos/48413. --- concepts/dict-methods/about.md | 4 +- .../mecha-munch-management/.docs/hints.md | 8 +- .../.docs/instructions.md | 10 +- .../.docs/introduction.md | 2 +- .../.docs/test_introduction.py | 167 ++++++++++++++++++ .../mecha-munch-management/.meta/exemplar.py | 16 +- .../mecha-munch-management/dict_methods.py | 10 +- 7 files changed, 192 insertions(+), 25 deletions(-) create mode 100644 exercises/concept/mecha-munch-management/.docs/test_introduction.py diff --git a/concepts/dict-methods/about.md b/concepts/dict-methods/about.md index 6dcf9b4ae7a..02f2dc21fa8 100644 --- a/concepts/dict-methods/about.md +++ b/concepts/dict-methods/about.md @@ -188,7 +188,7 @@ Where keys in the two dictionaries _overlap_, the `value` in `dict_one` will be 'Green Treeline': '#478559', 'Purple baseline': '#161748'} ``` -## Merge or Update Dictionaries Via the Union (`|`) Operators +## Merge or Update Dictionaries Using Union (`|` and `|=`) Operators Python 3.9 introduces a different means of merging `dicts`: the `union` operators. `dict_one | dict_two` will create a **new dictionary**, made up of the (`key`, `value`) pairs of `dict_one` and `dict_two`. @@ -271,7 +271,7 @@ Unless a _sort key_ is specified, the default sort is over dictionary `keys`. 'Misty Mountain Pink': '#f9c5bd'} ``` -## Transposing a Dictionaries Keys and Values +## Transposing Dictionary Keys and Values Swapping keys and values reliably in a dictionary takes a little work, but can be accomplished via a `loop` using `dict.items()` or in a dictionary comprehension. Safe swapping assumes that `dict` keys and values are both _hashable_. diff --git a/exercises/concept/mecha-munch-management/.docs/hints.md b/exercises/concept/mecha-munch-management/.docs/hints.md index 2d2f49e2cc8..2c8b35b2cc1 100644 --- a/exercises/concept/mecha-munch-management/.docs/hints.md +++ b/exercises/concept/mecha-munch-management/.docs/hints.md @@ -9,13 +9,13 @@ It's OK to be simple and direct with the functions you are writing. The dictionary section of the [official tutorial][dicts-docs] and the mapping type [official library reference][mapping-types-dict] are excellent places to look for more help with all these methods. -## 1. Add Item(s) to the Users Shopping Cart +## 1. Add Item(s) to the User's Shopping Cart - You will need to iterate through each item in `items_to_add`. - You can avoid a `KeyError` when a key is missing by using a `dict` [method][set-default] that takes a _default value_ as one of its arguments. - It is also possible to accomplish the same thing manually in the `loop` by using some checking and error handling, but the `dict` method is easier. -## 2. Read in Items Listed in the Users Notes App +## 2. Read in Items Listed in the User's Notes App - Remember, Python's got a method for _everything_. This one is a _classmethod_ that's an easy way to [populate a `dict`][fromkeys] with keys. - This `dict` method returns a _new dictionary_, populated with default values. If no value is given, the default value will become `None` @@ -25,13 +25,13 @@ The dictionary section of the [official tutorial][dicts-docs] and the mapping ty - Don't overthink this one! This can be solved in **one** `dict` method call. - The key word here is .... [_update_][update]. -## 4. Sort the Items in the User Cart +## 4. Sort the Items in the User's Cart - What method would you call to get an [iterable view of items][items] in the dictionary? - If you had a `list` or a `tuple`, what [`built-in`][builtins] function might you use to sort them? - The built-in function you want is the one that returns a _copy_, and doesn't mutate the original. -## 5. Send User Shopping Cart to Store for Fulfillment +## 5. Send the User's Shopping Cart to the Store for Fulfillment - Having a fresh, empty dictionary here as the `fulfillment_cart` might be handy for adding in items. - `Looping` through the members of the cart might be the most direct way of accessing things here. diff --git a/exercises/concept/mecha-munch-management/.docs/instructions.md b/exercises/concept/mecha-munch-management/.docs/instructions.md index e679db79742..fc3d0ff7cb1 100644 --- a/exercises/concept/mecha-munch-management/.docs/instructions.md +++ b/exercises/concept/mecha-munch-management/.docs/instructions.md @@ -1,10 +1,10 @@ # Instructions -Mecha Munchâ„¢, a grocery shopping automation company has just hired you to work on their ordering app. +Mecha Munchâ„¢, a grocery shopping automation company, has just hired you to work on their ordering app. Your team is tasked with building an MVP (_[minimum viable product][mvp]_) that manages all the basic shopping cart activities, allowing users to add, remove, and sort their grocery orders. Thankfully, a different team is handling all the money and check-out functions! -## 1. Add Item(s) to the Users Shopping Cart +## 1. Add Item(s) to the User's Shopping Cart The MVP should allow the user to add items to their shopping cart. This could be a single item or multiple items at once. @@ -26,12 +26,12 @@ It should return a new/updated shopping cart dictionary for the user. {'Banana': 5, 'Apple': 2, 'Orange': 2, 'Blueberries': 1} ``` -## 2. Read in Items Listed in the Users Notes App +## 2. Read in Items Listed in the User's Notes App Uh-oh. Looks like the product team is engaging in [feature creep][feature creep]. They want to add extra functionality to the MVP. -The application now has to create a shopping cart by reading items off a users notes app. +The application now has to create a shopping cart by reading items off a user's notes app. Convenient for the users, but slightly more work for the team. Create the function `read_notes()` that can take any list-like iterable as an argument. @@ -97,7 +97,7 @@ Create the function `sort_entries()` that takes a shopping cart/dictionary ## 5. Send User Shopping Cart to Store for Fulfillment -The app needs to send a given users cart to the store for fulfillment. +The app needs to send a given user's cart to the store for fulfillment. However, the shoppers in the store need to know which store aisle the item can be found in and if the item needs refrigeration. So (_rather arbitrarily_) the "fulfillment cart" needs to be sorted in reverse alphabetical order with item quantities combined with location and refrigeration information. diff --git a/exercises/concept/mecha-munch-management/.docs/introduction.md b/exercises/concept/mecha-munch-management/.docs/introduction.md index b2938b8c216..6f63d8acd60 100644 --- a/exercises/concept/mecha-munch-management/.docs/introduction.md +++ b/exercises/concept/mecha-munch-management/.docs/introduction.md @@ -171,7 +171,7 @@ Where keys in the two dictionaries _overlap_, the `value` in `dict_one` will be 'Green Treeline': '#478559', 'Purple baseline': '#161748'} ``` -## Merge or Update Dictionaries Via the Union (`|`) Operators +## Merge or Update Dictionaries Using Union (`|` and `|=`) Operators Python 3.9 introduces a different means of merging `dicts`: the `union` operators. `dict_one | dict_two` will create a **new dictionary**, made up of the (`key`, `value`) pairs of `dict_one` and `dict_two`. diff --git a/exercises/concept/mecha-munch-management/.docs/test_introduction.py b/exercises/concept/mecha-munch-management/.docs/test_introduction.py new file mode 100644 index 00000000000..1fecc92ffb9 --- /dev/null +++ b/exercises/concept/mecha-munch-management/.docs/test_introduction.py @@ -0,0 +1,167 @@ +"""pytest file built from introduction.md""" + + +def session_00001_line_17(): + r""" + >>> palette_I = {'Grassy Green': '#9bc400', 'Purple Mountains Majesty': '#8076a3', 'Misty Mountain Pink': '#f9c5bd'} + + # Looking for the value associated with key "Rock Brown". + # The key does not exist, so it is added with the default value, and the value is returned. + >>> palette_I.setdefault('Rock Brown', '#694605') + '#694605' + + # The (key, default value) pair has now been added to the dictionary. + >>> palette_I + {'Grassy Green': '#9bc400', 'Purple Mountains Majesty': '#8076a3', 'Misty Mountain Pink': '#f9c5bd', 'Rock Brown': '#694605'} + """ + + +def session_00002_line_35(): + r""" + >>> new_dict = dict.fromkeys(['Grassy Green', 'Purple Mountains Majesty', 'Misty Mountain Pink'], 'fill in hex color here') + + {'Grassy Green': 'fill in hex color here', + 'Purple Mountains Majesty': 'fill in hex color here', + 'Misty Mountain Pink': 'fill in hex color here'} + """ + + +def session_00003_line_50(): + r""" + >>> palette_I = {'Grassy Green': '#9bc400', 'Purple Mountains Majesty': '#8076a3', 'Misty Mountain Pink': '#f9c5bd'} + + # Using .keys() returns a list of keys. + >>> palette_I.keys() + dict_keys(['Grassy Green', 'Purple Mountains Majesty', 'Misty Mountain Pink']) + + # Using .values() returns a list of values. + >>> palette_I.values() + dict_values(['#9bc400', '#8076a3', '#f9c5bd']) + + # Using .items() returns a list of (key, value) tuples. + >>> palette_I.items() + dict_items([('Grassy Green', '#9bc400'), ('Purple Mountains Majesty', '#8076a3'), ('Misty Mountain Pink', '#f9c5bd')]) + + # Views are dynamic. Changing values in the dict changes all of the associated views. + >>> palette_I['Purple Mountains Majesty'] = (128, 118, 163) + >>> palette_I['Deep Red'] = '#932432' + + >>> palette_I.values() + dict_values(['#9bc400', (128, 118, 163), '#f9c5bd', '#932432']) + + >>> palette_I.keys() + dict_keys(['Grassy Green', 'Purple Mountains Majesty', 'Misty Mountain Pink', 'Deep Red']) + + >>> palette_I.items() + dict_items([('Grassy Green', '#9bc400'), ('Purple Mountains Majesty', (128, 118, 163)), ('Misty Mountain Pink', '#f9c5bd'), ('Deep Red', '#932432')]) + """ + + +def session_00004_line_88(): + r""" + >>> palette_II = {'Factory Stone Purple': '#7c677f', 'Green Treeline': '#478559', 'Purple baseline': '#161748'} + + # Iterating in insertion order (First in, first out) + >>> for item in palette_II.items(): + ... print(item) + ... + ('Factory Stone Purple', '#7c677f') + ('Green Treeline', '#478559') + ('Purple baseline', '#161748') + + + # Iterating in the reverse direction. (Last in, first out) + >>> for item in reversed(palette_II.items()): + ... print (item) + ... + ('Purple baseline', '#161748') + ('Green Treeline', '#478559') + ('Factory Stone Purple', '#7c677f') + """ + + +def session_00005_line_116(): + r""" + # Default ordering for a dictionary is insertion order (First in, first out). + >>> color_palette = {'Grassy Green': '#9bc400', + ... 'Purple Mountains Majesty': '#8076a3', + ... 'Misty Mountain Pink': '#f9c5bd', + ... 'Factory Stone Purple': '#7c677f', + ... 'Green Treeline': '#478559', + ... 'Purple baseline': '#161748'} + + # The default sort order for a dictionary uses the keys. + >>> sorted_palette = dict(sorted(color_palette.items())) + >>> sorted_palette + {'Factory Stone Purple': '#7c677f', 'Grassy Green': '#9bc400', 'Green Treeline': '#478559', 'Misty Mountain Pink': '#f9c5bd', 'Purple Mountains Majesty': '#8076a3', 'Purple baseline': '#161748'} + """ + + +def session_00006_line_140(): + r""" + >>> palette_I = {'Grassy Green': '#9bc400', + ... 'Purple Mountains Majesty': '#8076a3', + ... 'Misty Mountain Pink': '#f9c5bd'} + + >>> palette_II = {'Factory Stone Purple': '#7c677f', + ... 'Green Treeline': '#478559', + ... 'Purple Baseline': '#161748'} + + >>> palette_I.update(palette_II) + + # Note that new items from palette_II are added. + >>> palette_I + {'Grassy Green': '#9bc400', 'Purple Mountains Majesty': '#8076a3', 'Misty Mountain Pink': '#f9c5bd', 'Factory Stone Purple': '#7c677f', 'Green Treeline': '#478559', 'Purple Baseline': '#161748'} + """ + + +def session_00007_line_158(): + r""" + >>> palette_I = {'Grassy Green': '#9bc400', 'Purple Mountains Majesty': '#8076a3', 'Misty Mountain Pink': '#f9c5bd', + 'Factory Stone Purple': '#7c677f', 'Green Treeline': '#478559', 'Purple baseline': '#161748'} + >>> palette_III = {'Grassy Green': (155, 196, 0), 'Purple Mountains Majesty': (128, 118, 163), + 'Misty Mountain Pink': (249, 197, 189)} + >>> palette_I.update(palette_III) + + # Overlapping values in palette_I are replaced with values from palette_III + >>> palette_I + {'Grassy Green': (155, 196, 0), + 'Purple Mountains Majesty': (128, 118, 163), + 'Misty Mountain Pink': (249, 197, 189), + 'Factory Stone Purple': '#7c677f', + 'Green Treeline': '#478559', 'Purple baseline': '#161748'} + """ + + +def session_00008_line_180(): + r""" + >>> palette_I = {'Grassy Green': '#9bc400', 'Purple Mountains Majesty': '#8076a3', 'Misty Mountain Pink': '#f9c5bd'} + >>> palette_II = {'Factory Stone Purple': '#7c677f', 'Green Treeline': '#478559', 'Purple baseline': '#161748'} + >>> new_dict = palette_I | palette_II + >>> new_dict + ... + {'Grassy Green': '#9bc400', + 'Purple Mountains Majesty': '#8076a3', + 'Misty Mountain Pink': '#f9c5bd', + 'Factory Stone Purple': '#7c677f', + 'Green Treeline': '#478559', + 'Purple baseline': '#161748'} + """ + + +def session_00009_line_196(): + r""" + >>> palette_III = {'Grassy Green': (155, 196, 0), + ... 'Purple Mountains Majesty': (128, 118, 163), + ... 'Misty Mountain Pink': (249, 197, 189)} + + >>> new_dict |= palette_III + >>> new_dict + ... + {'Grassy Green': (155, 196, 0), + 'Purple Mountains Majesty': (128, 118, 163), + 'Misty Mountain Pink': (249, 197, 189), + 'Factory Stone Purple': '#7c677f', + 'Green Treeline': '#478559', + 'Purple baseline': '#161748'} + """ diff --git a/exercises/concept/mecha-munch-management/.meta/exemplar.py b/exercises/concept/mecha-munch-management/.meta/exemplar.py index 221a4c259e1..e5074607cba 100644 --- a/exercises/concept/mecha-munch-management/.meta/exemplar.py +++ b/exercises/concept/mecha-munch-management/.meta/exemplar.py @@ -48,23 +48,23 @@ def update_recipes(ideas, recipe_updates): def sort_entries(cart): - """Sort a users shopping cart in alphabetically order. + """Sort a user's shopping cart in alphabetical order. - Parameters: - cart (dict): A users shopping cart dictionary. + Parameters: + cart (dict): A user's shopping cart dictionary. - Returns: - dict: A sers shopping cart sorted in alphabetical order. - """ + Returns: + dict: A user's shopping cart sorted in alphabetical order. + """ return dict(sorted(cart.items())) def send_to_store(cart, aisle_mapping): - """Combine users order to aisle and refrigeration information. + """Combine user's order to aisle and refrigeration information. Parameters: - cart (dict): The users shopping cart dictionary. + cart (dict): The user's shopping cart dictionary. aisle_mapping (dict): The aisle and refrigeration information dictionary. Returns: diff --git a/exercises/concept/mecha-munch-management/dict_methods.py b/exercises/concept/mecha-munch-management/dict_methods.py index f6804281d21..a2a535c4b7b 100644 --- a/exercises/concept/mecha-munch-management/dict_methods.py +++ b/exercises/concept/mecha-munch-management/dict_methods.py @@ -43,23 +43,23 @@ def update_recipes(ideas, recipe_updates): def sort_entries(cart): - """Sort a users shopping cart in alphabetically order. + """Sort a user's shopping cart in alphabetical order. Parameters: - cart (dict): A users shopping cart dictionary. + cart (dict): A user's shopping cart dictionary. Returns: - dict: A sers shopping cart sorted in alphabetical order. + dict: A user's shopping cart sorted in alphabetical order. """ pass def send_to_store(cart, aisle_mapping): - """Combine users order to aisle and refrigeration information. + """Combine user's order to aisle and refrigeration information. Parameters: - cart (dict): The users shopping cart dictionary. + cart (dict): The user's shopping cart dictionary. aisle_mapping (dict): The aisle and refrigeration information dictionary. Returns: From 62c1930681fdc022193990dfd1d62a2e77af240a Mon Sep 17 00:00:00 2001 From: BethanyG Date: Wed, 13 May 2026 14:44:32 -0700 Subject: [PATCH 2/2] Deleted unneeded test file. --- .../.docs/test_introduction.py | 167 ------------------ 1 file changed, 167 deletions(-) delete mode 100644 exercises/concept/mecha-munch-management/.docs/test_introduction.py diff --git a/exercises/concept/mecha-munch-management/.docs/test_introduction.py b/exercises/concept/mecha-munch-management/.docs/test_introduction.py deleted file mode 100644 index 1fecc92ffb9..00000000000 --- a/exercises/concept/mecha-munch-management/.docs/test_introduction.py +++ /dev/null @@ -1,167 +0,0 @@ -"""pytest file built from introduction.md""" - - -def session_00001_line_17(): - r""" - >>> palette_I = {'Grassy Green': '#9bc400', 'Purple Mountains Majesty': '#8076a3', 'Misty Mountain Pink': '#f9c5bd'} - - # Looking for the value associated with key "Rock Brown". - # The key does not exist, so it is added with the default value, and the value is returned. - >>> palette_I.setdefault('Rock Brown', '#694605') - '#694605' - - # The (key, default value) pair has now been added to the dictionary. - >>> palette_I - {'Grassy Green': '#9bc400', 'Purple Mountains Majesty': '#8076a3', 'Misty Mountain Pink': '#f9c5bd', 'Rock Brown': '#694605'} - """ - - -def session_00002_line_35(): - r""" - >>> new_dict = dict.fromkeys(['Grassy Green', 'Purple Mountains Majesty', 'Misty Mountain Pink'], 'fill in hex color here') - - {'Grassy Green': 'fill in hex color here', - 'Purple Mountains Majesty': 'fill in hex color here', - 'Misty Mountain Pink': 'fill in hex color here'} - """ - - -def session_00003_line_50(): - r""" - >>> palette_I = {'Grassy Green': '#9bc400', 'Purple Mountains Majesty': '#8076a3', 'Misty Mountain Pink': '#f9c5bd'} - - # Using .keys() returns a list of keys. - >>> palette_I.keys() - dict_keys(['Grassy Green', 'Purple Mountains Majesty', 'Misty Mountain Pink']) - - # Using .values() returns a list of values. - >>> palette_I.values() - dict_values(['#9bc400', '#8076a3', '#f9c5bd']) - - # Using .items() returns a list of (key, value) tuples. - >>> palette_I.items() - dict_items([('Grassy Green', '#9bc400'), ('Purple Mountains Majesty', '#8076a3'), ('Misty Mountain Pink', '#f9c5bd')]) - - # Views are dynamic. Changing values in the dict changes all of the associated views. - >>> palette_I['Purple Mountains Majesty'] = (128, 118, 163) - >>> palette_I['Deep Red'] = '#932432' - - >>> palette_I.values() - dict_values(['#9bc400', (128, 118, 163), '#f9c5bd', '#932432']) - - >>> palette_I.keys() - dict_keys(['Grassy Green', 'Purple Mountains Majesty', 'Misty Mountain Pink', 'Deep Red']) - - >>> palette_I.items() - dict_items([('Grassy Green', '#9bc400'), ('Purple Mountains Majesty', (128, 118, 163)), ('Misty Mountain Pink', '#f9c5bd'), ('Deep Red', '#932432')]) - """ - - -def session_00004_line_88(): - r""" - >>> palette_II = {'Factory Stone Purple': '#7c677f', 'Green Treeline': '#478559', 'Purple baseline': '#161748'} - - # Iterating in insertion order (First in, first out) - >>> for item in palette_II.items(): - ... print(item) - ... - ('Factory Stone Purple', '#7c677f') - ('Green Treeline', '#478559') - ('Purple baseline', '#161748') - - - # Iterating in the reverse direction. (Last in, first out) - >>> for item in reversed(palette_II.items()): - ... print (item) - ... - ('Purple baseline', '#161748') - ('Green Treeline', '#478559') - ('Factory Stone Purple', '#7c677f') - """ - - -def session_00005_line_116(): - r""" - # Default ordering for a dictionary is insertion order (First in, first out). - >>> color_palette = {'Grassy Green': '#9bc400', - ... 'Purple Mountains Majesty': '#8076a3', - ... 'Misty Mountain Pink': '#f9c5bd', - ... 'Factory Stone Purple': '#7c677f', - ... 'Green Treeline': '#478559', - ... 'Purple baseline': '#161748'} - - # The default sort order for a dictionary uses the keys. - >>> sorted_palette = dict(sorted(color_palette.items())) - >>> sorted_palette - {'Factory Stone Purple': '#7c677f', 'Grassy Green': '#9bc400', 'Green Treeline': '#478559', 'Misty Mountain Pink': '#f9c5bd', 'Purple Mountains Majesty': '#8076a3', 'Purple baseline': '#161748'} - """ - - -def session_00006_line_140(): - r""" - >>> palette_I = {'Grassy Green': '#9bc400', - ... 'Purple Mountains Majesty': '#8076a3', - ... 'Misty Mountain Pink': '#f9c5bd'} - - >>> palette_II = {'Factory Stone Purple': '#7c677f', - ... 'Green Treeline': '#478559', - ... 'Purple Baseline': '#161748'} - - >>> palette_I.update(palette_II) - - # Note that new items from palette_II are added. - >>> palette_I - {'Grassy Green': '#9bc400', 'Purple Mountains Majesty': '#8076a3', 'Misty Mountain Pink': '#f9c5bd', 'Factory Stone Purple': '#7c677f', 'Green Treeline': '#478559', 'Purple Baseline': '#161748'} - """ - - -def session_00007_line_158(): - r""" - >>> palette_I = {'Grassy Green': '#9bc400', 'Purple Mountains Majesty': '#8076a3', 'Misty Mountain Pink': '#f9c5bd', - 'Factory Stone Purple': '#7c677f', 'Green Treeline': '#478559', 'Purple baseline': '#161748'} - >>> palette_III = {'Grassy Green': (155, 196, 0), 'Purple Mountains Majesty': (128, 118, 163), - 'Misty Mountain Pink': (249, 197, 189)} - >>> palette_I.update(palette_III) - - # Overlapping values in palette_I are replaced with values from palette_III - >>> palette_I - {'Grassy Green': (155, 196, 0), - 'Purple Mountains Majesty': (128, 118, 163), - 'Misty Mountain Pink': (249, 197, 189), - 'Factory Stone Purple': '#7c677f', - 'Green Treeline': '#478559', 'Purple baseline': '#161748'} - """ - - -def session_00008_line_180(): - r""" - >>> palette_I = {'Grassy Green': '#9bc400', 'Purple Mountains Majesty': '#8076a3', 'Misty Mountain Pink': '#f9c5bd'} - >>> palette_II = {'Factory Stone Purple': '#7c677f', 'Green Treeline': '#478559', 'Purple baseline': '#161748'} - >>> new_dict = palette_I | palette_II - >>> new_dict - ... - {'Grassy Green': '#9bc400', - 'Purple Mountains Majesty': '#8076a3', - 'Misty Mountain Pink': '#f9c5bd', - 'Factory Stone Purple': '#7c677f', - 'Green Treeline': '#478559', - 'Purple baseline': '#161748'} - """ - - -def session_00009_line_196(): - r""" - >>> palette_III = {'Grassy Green': (155, 196, 0), - ... 'Purple Mountains Majesty': (128, 118, 163), - ... 'Misty Mountain Pink': (249, 197, 189)} - - >>> new_dict |= palette_III - >>> new_dict - ... - {'Grassy Green': (155, 196, 0), - 'Purple Mountains Majesty': (128, 118, 163), - 'Misty Mountain Pink': (249, 197, 189), - 'Factory Stone Purple': '#7c677f', - 'Green Treeline': '#478559', - 'Purple baseline': '#161748'} - """