Code Toolkit: Python, Spring 2026

Week 7 — Wednesday, March 4 — Class notes

  1. New concept: working with many things
  2. Background and examples
  3. Lists

I. Working with may things

Today we will learn about working with many things.

Two weeks ago (week 5, and reviewed during week 6) we learned how to draw many items using loops, but you couldn't move each item around individually. Thus far, if you wanted to move many things, you would have had to hard code new variables for each one. Today we will learn how to draw many things and move many things, using a thing called lists.

In Python, a list is like a collection of variables. In a way, this topic is like a mashup of variables and loops:

» With loops, instead of drawing many things line-by-line, you can create a loop which draws many things at once, even a dynamic number of things.

» With lists, instead of declaring each variable line-by-line, you can create one list that declares many variables at once, and can even allow you to work with a dynamic number of variables.

This topic is an introduction to one of the most interesting and important aspects of computer science: data structures. The term data structure refers to a way of organizing many variables together for efficient and convenient use. The type of variable organization that you'll need to use in a given situation (i.e., the type of data structure) depends on the problem that you are trying to solve. In addition to lists, Python provides many other data structures, such as: sets, tuples, and dictionaries, among others. And beyond these data structures that come "built-in" to Python, in computer science there are many other more complex kinds of data structures that go by names like: stacks, queues, linked lists, and trees. But in a certain sense, lists are the most fundamental data structure: we could think about ways to implement all these other more complicated data structures using just lists, so maybe we can think about lists as underlying all these others.

Data structures allow you to start to think about modeling: how to organize your variables and other code in a way that matches the thing that you're trying to do. A good data structure could make your program much easier to implement and to read, while an inappropriately chosen data structure could make the thing that you're trying to do very hard and potentially less efficient in terms of computing resources.

(jump back up to table of contents)

II. Background and examples

Gene Kogan

Since lists are used to manage many things, they are often used to implement things like swarms, or herds of objects that behave as if they are acting independently or on their own.

Daniel Shiffman, a professor at NYU in the Interactive Telecommunications Program (ITP) graduate program, uses lists and other data structures to implement swarms that are used to simulate natural phenomenon like animals, plants, clouds, flowing liquids, and others.

For example, here is a video that demonstrates a simulation of "flocking", like birds or fish moving together. (It's a very cute video.) Shiffman's book Nature of Code offers detailed lessons in how to achieve affects like this.

Another, more aesthetically developed, example is this flocking demo by Gene Kogan, using a well-known algorithm developed by Craig Reynolds known as "Boids".

And another great example is the project We Feel Fine by Jonathan Harris and Sep Kamvar. This project was made in 2006 using Processing and unfortuntely can be a bit difficult to run that now. (You will probably need to install Java for your browswer and OS version.) But there is documentation online, like this video that demonstrates how the project functioned.

(jump back up to table of contents)

III. Lists