Lists, Dictionaries and Loops
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
- Why do you need lists, dictionaries and loops?
- Lists: many items in order
- Dictionaries: values with labels
- Loops: do it for every item
- List comprehensions and nested data
- Try it: the loop stepper
- Common mistakes
- Explain it to a friend
- Key takeaways
10 quiz questions at the end.
The full lesson, with interactive demos and the quiz, opens after you sign in with Google. It is free.