Spot the problem in this AI code

Python. The task: "Write a function that starts a shopping cart for a user, with optional starting items." Read the code, then pick what goes wrong.

cart.py
def new_cart(user_id, items=[]):
    """Start a cart for a user, optionally with some items."""
    return {"user": user_id, "items": items}


def add_item(cart, sku):
    cart["items"].append(sku)
    return cart

We start a cart for u1, add a mug, then start a cart for u2. What goes wrong?

  1. add_item returns None, so the caller loses the cart
  2. It raises a KeyError, because the cart has no "items" key yet
  3. Each cart gets its own copy of the list, so add_item changes nothing
  4. Carts made without items all share the same list, so u2 starts with u1's mug

Show the answerHide the answer

Answer D: Carts made without items all share the same list, so u2 starts with u1's mug

We made a cart for u1, added 'mug', then made a new cart for u2, and it printed {'user': 'u2', 'items': ['mug']} instead of an empty cart. Python builds the default items=[] once, when the function is defined, so every cart made without items shares that same list (same list object: True). Defaulting to None and creating a fresh list inside the function printed {'user': 'u2', 'items': []}.

The fix: cart.py
def new_cart(user_id, items=None):
    """Start a cart for a user, optionally with some items."""
    return {"user": user_id, "items": [] if items is None else items}


def add_item(cart, sku):
    cart["items"].append(sku)
    return cart

Explain it at your depth

The code is already in the box below. Pick a level and press Explain it, and Vibe explains it in plain English. Free, no account.

cart.py

Up to 1,500 characters (about 60 lines). Your code is sent to Unvibe and Anthropic to write the explanation. Don't paste keys or passwords. Common key formats are refused.

Vibe9 lines selected

Press Explain it for the sample, or paste your own code first.

Explain code beside your editor

When your AI tool writes code, select the code in any app and press the shortcut. On a Mac that's Control+U, not Command+U (⌘U only works in Cursor and VS Code with the editor bridge). On Windows it's Ctrl+Alt+U. Vibe explains it beside your editor, you can ask it why, and Test me checks that you followed. Unvibe is a free app for Mac and Windows.

Install on Mac

curl -fsSL https://unvibe.site/install.sh | bash

Paste into Terminal. Unvibe isn't notarized by Apple yet, so this is the smooth path.

No install warning? Use Unvibe in your browser

Opening the .dmg the first time
  1. Open the .dmg and drag Unvibe to Applications.
  2. Open it once; macOS says it can't verify it. Click Done, not the blue Move to Trash.
    macOS dialog: “Unvibe” Not Opened, with a blue Move to Trash button on top and Done under it
    Real screen, macOS 26. On macOS 15 the two buttons sit side by side.
  3. System Settings › Privacy & Security, scroll down to Security, then press Open Anyway. Confirm, then enter your Mac password. The button shows for about an hour after you try to open Unvibe.
    macOS Privacy & Security, Security section: Unvibe was blocked to protect your Mac, with the Open Anyway button
    Real screen, macOS 15

The Terminal line checks the download against the published SHA-256 and Unvibe's self-signed signature before it installs anything. More help with the first open