Lists, Dictionaries and Loops

22 min read

Real AI work deals with many things at once. You may have many prompts, many token counts, or a whole chat of messages. In this lesson you learn the list and the dictionary, which hold many values together. You also learn the loop, which repeats some work for every item.

New words

list
Many values kept in order, like numbered seats in a train coach.
index
The seat number of an item in a list, starting from 0.
dictionary
Values kept under labels, like the contact list in your phone.
key and value
The key is the label, and the value is the data kept under it.
loop
Code that repeats once for every item, like a teacher checking each answer sheet.
accumulator
A variable that collects a running total, adding a little on each lap.
list comprehension
A short, one-line way to build a new list from an old one.

What you will learn

  1. Why do you need lists, dictionaries and loops?
  2. Lists: many items in order
  3. Dictionaries: values with labels
  4. Loops: do it for every item
  5. List comprehensions and nested data
  6. Try it: the loop stepper
  7. Common mistakes
  8. Explain it to a friend
  9. Key takeaways

10 quiz questions at the end.

Start this lesson

The full lesson, with interactive demos and the quiz, opens after you sign in with Google. It is free.

All lessons · Back to the roadmap