Checkout With Surprises

Python for AIHard+10 XP+10

Checkout With Surprises

A self-checkout scans a list of item names. The menu is a dictionary of item name to price. Some scanned items might not be on the menu.

Write checkout(menu, scanned) that returns a list of two things: [total, unknown].

  • total is the price of every scanned item that is on the menu. Count repeats every time.
  • unknown is a list of the scanned names that are not on the menu. Each one appears only once, in the order it was first scanned.
  • An empty scan gives [0, []].

Examples

menu = {'milk': 30, 'bread': 25}
scanned = ['milk', 'soap', 'milk', 'soap']
returns [60, ['soap']]
menu = {"milk": 30, "bread": 25, "eggs": 60}
scanned = ["bread", "eggs", "bread"]
returns [110, []]
menu = {"milk": 30}
scanned = []
returns [0, []]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run