Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions concepts/dict-methods/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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_.
Expand Down
8 changes: 4 additions & 4 deletions exercises/concept/mecha-munch-management/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions exercises/concept/mecha-munch-management/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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(<notes>)` that can take any list-like iterable as an argument.
Expand Down Expand Up @@ -97,7 +97,7 @@ Create the function `sort_entries(<cart>)` 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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
16 changes: 8 additions & 8 deletions exercises/concept/mecha-munch-management/.meta/exemplar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions exercises/concept/mecha-munch-management/dict_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading