Minute Two: A Simple Dictionary

You take so long reading the Harry Potter books that your friend sends you an updated list. He has included the authors' names this time.

Stanislaw Lem: Memoirs Found in a Bathtub
Neal Stephenson: Snowcrash
Daniel Clowes: Ghost World

The dictionary above has no order, but matches author's names with the book titles. Your friend's hope is that having the author's name will help you find the book.

In YAML, such a dictionary is called a map. Maps are commonly used to pair data up. On the left side of the colon is the key. On the right is the value.

The key is used as an index for retrieving data from a map.

In PHP or Ruby:

print $books_by_author['Daniel Clowes'];

Would print:

Ghost World

A Map In Sequence

Your friend sends you an updated list that includes the author's name, the title of book and the order in which he wants you to read them.
---
- Stanislaw Lem: Memoirs Found in a Bathtub
- Neal Stephenson: Snowcrash
- Daniel Clowes: Ghost World

Each item in the sequence above contains a map. When one sort of collection contains another, this is called nesting.

Next up: MinuteThree

Last edited Dec 21, 2009 at 9:09 PM by BurtHarris, version 3

Comments

No comments yet.