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/.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: