Lists and Dictionaries
These two data structures are fundamental for working with AI APIs and managing conversation history.
Lists
Ordered, mutable collections:
messages = ["Hello", "How are you?", "Goodbye"]
messages.append("See you later")
first_message = messages[0]Dictionaries
Key-value pairs — the format most AI APIs use:
message = {
"role": "user",
"content": "Hello!"
}Why These Matter for AI
- Lists store conversation history
- Dictionaries format API messages
- List of dicts is the standard format:
messages = [
{"role": "system", "content": "You are helpful"},
{"role": "user", "content": "Hi!"}
]