Python — lists, loops and dictionaries
Store multiple values in lists and dictionaries, iterate through them with for-loops, and build new lists from old ones — the foundation for all data handling in Python.
Code
invoice_amounts = [1200.5, 1500.0, 980.8, 1720.2]
total = 0
for amount in invoice_amounts:
total += amount
print(total / len(invoice_amounts)) # average
large = [a for a in invoice_amounts if a > 1200] # list comprehension
len() gives the count, invoice_amounts[0] the first item, invoice_amounts[-1] the last.
Intuition
A dictionary maps key → value. Perfect for counting:
products = ["coffee", "tea", "coffee", "juice", "coffee"]
counts = {}
for p in products:
counts[p] = counts.get(p, 0) + 1
# {'coffee': 3, 'tea': 1, 'juice': 1}
Almost all data you encounter in AI consists of lists of numbers (vectors), lists of lists (matrices), or dictionaries (records with named fields). Getting comfortable here makes the rest much easier.
Mastery means
- Write a for-loop that filters and sums values
- Use a dictionary to count occurrences
Prerequisites
- CPython — the basicsrequired
Sign in to do the exercises and build your mastery up.
Sources
Leads to
- CPython — files, CSV and JSON
- CRandomness and games in Python
- DGradient descent
- DJupyter and notebooks
- DNumPy — arrays and vectorisation
- DPyTorch — tensors and autograd
- DPython — functions, scope and exceptions
- DThe grid world: your first RL agent
- DTime complexity and big-O notation
- DTokenisation
- Dn-gram language models
- EMonte Carlo methods
Part of the goals (37)
- The developer's toolbox
- Language models in practice
- From blocks to Python
- Statistics for experiments
- Train an agent with reward
- Image classification with convolutional networks
- Training neural networks for real
- Train your first neural network
- Systems knowledge for AI engineers
- Run models more cheaply: quantisation
- Build a memory system for an agent
- Build a transformer from scratch
- Data: collect, clean, document
- Classical machine learning in practice
- Classical ML for real
- Understand how generative AI works
- Fine-tune and run your own models
- Fine-tune a model with LoRA
- AI safety in practice
- Deep reinforcement learning
- Build an agent you can trust
- Foundations of computer science
- The mathematics behind the models
- Evals in practice
- Frontier Lab — an independent research project
- Multimodal systems
- Build a RAG pipeline with traceable sources
- Build a voice interface
- Reproduce a paper
- Responsible AI in practice
- AI in production
- Build an NLP system end to end
- Build an AI service that survives production
- An AI service in operation
- Generative models in depth
- Interpreting a language model
- AI, ethics and society