Chapter 8Arrays and Iterators

Welcome back! Let’s write a program that asks us to type in as many words as we want (one word per line, continuing until we just press Enter on an empty line) and then repeats the words back to us in alphabetical order. OK?

So…first we’ll—uh…um…hmmm…. Well, we could—er…em….

You know, I don’t think we can do it. We need a way to store an unknown number of words and to keep track of them altogether so they don’t get mixed up with other variables. We need to put them in some sort of a list. We need arrays.

An array is just a list in your computer. Every slot in the list acts like a variable: you can see what object a particular slot points to, and you can make it point to a different object. Let’s take a look ...

Get Learn to Program, 2nd Edition 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.