What You Get on Each Step

Different iterables hand you different things on each step. Knowing what arrives is the whole game:

List/array → each item

String → each character

Dictionary → each key (then you look up the value)

Set → each unique member

Range → each number in a sequence

Getting the keys and values

PYTHON

record = {"name": "Ruby", "city": "Jackson"}

print(list(record.keys()))
print(list(record.values()))

JAVASCRIPT

const record = { name: "Ruby", city: "Jackson" };

console.log(Object.keys(record));
console.log(Object.values(record)); 
Compare → Python asks the dictionary itself: record.keys(). JavaScript asks the built-in Object helper: Object.keys(record). Different grammar, identical result, a walkable sequence of the labels.
EXAMPLE
loading editor…
YOUR TURN
Your turn → Make a dictionary describing yourself, with your name, your city and a favorite book, then print its keys and its values.
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: range: Generating a Sequence to Walk →
← Back