Lists as Data Structures

Sometimes you don’t need a long, expanding list of entries. Sometimes you have just a few things that you want to keep organized and together. You can use lists to create little structures for your things, much like the color list gave structure to red, green, and blue values.

For instance, consider an app that keeps track of bills that need to be paid each month. For each bill, the user inputs a name (text), a day of the month it is due (number), and an amount (number). We can use a list to bind these three things together into a single unit that we can move around. Figure 6.18 shows such a list, which we can then consider to be “a bill.”

Figure 6.18 A list that provides structure for “a bill,” made from a name, a ...

Get Learning MIT App Inventor: A Hands-On Guide to Building Your Own Android Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.