Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created September 8, 2023 12:41
Show Gist options
  • Save stephengruppetta/4f5a7f4ae88b06cbe5178feeb2e5242e to your computer and use it in GitHub Desktop.
Save stephengruppetta/4f5a7f4ae88b06cbe5178feeb2e5242e to your computer and use it in GitHub Desktop.
from typing import NamedTuple
shopping_list = [
"Biscuits",
"Bread",
"Butter",
"Berries",
"Bananas",
"Bagels",
]
class SupermarketShelves(NamedTuple):
aisle: int
section: str
supermarket = {
"Bread": SupermarketShelves(3, "B"),
"Biscuits": SupermarketShelves(4, "D"),
"Butter": SupermarketShelves(1, "B"),
"Berries": SupermarketShelves(5, "C"),
"Bananas": SupermarketShelves(5, "C"),
}
def order_shopping_list(shopping_list, supermarket):
sorted_items = sorted(
shopping_list,
key=lambda item: supermarket.get(item).aisle,
)
return sorted_items
items_to_buy = order_shopping_list(shopping_list, supermarket)
print("Time to start your shopping:")
print(*items_to_buy, sep="\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment