1. Key and Value

Dictionaries

A dictionary stores values under names called keys: song = {"kick": [1, 5], "snare": [3, 7]}. Look one up with song["kick"], add one with song["hihat"] = [2, 4].

Lesson 1: a song stored by drum name.

song = {"kick": [1, 5], "snare": [3, 7]}
song["hihat"] = [1, 2, 3, 4]
kick(song["kick"])
snare(song["snare"])
hihat(song["hihat"])
The beat it plays
hihat
snare
kick
1234
5678
…and in RockBlocks
Hi-Hat (Closed)
Snare Drum
Bass Drum
🎯 0/4 · 🥁 0 solved · 🏅 0

Challenge A:beats = {"kick": 1, "snare": 3}. Play kick(beats["kick"]) and snare(beats["snare"]).

Goal
snare
kick
1234