When you think about it, arrays, collections, dictionaries, and other similar storage structures provide a means to manage related items. Yes, you can stick any data in the data structure, but normally, the data elements are going to have some kind of relation. Arrays and other data management structures are like apartment mailboxes, with an individual mailbox to hold each individual data element.
The difference between data storage structures comes in the complexity of the data they can hold and the data management functionality they provide. An array (the term is used generically here to mean any ordered storage mechanism that follows the rules of arrays) is an older, simplistic storage mechanism that still sees plenty of use precisely because it’s so simple. If you only need to hold a list of items, there isn’t a good reason to use a more complex data storage mechanism.
As applications increased in complexity, developers also encountered data with greater storage needs. Collections and dictionaries are just two of many storage mechanisms designed to meet these needs (and the only two that IronPython supports directly). Collections introduce the idea of enumerated access, while dictionaries provide an easier method than numbering to locate a particular data element. You’ll discover that these two storage mechanisms provide other functionality as well.
Working with Tuples, Lists, and Arrays
Arrays are the backbone of in-memory data storage for most programming languages. At a basic level, an array is simply a sequence of memory entries. These entries normally reside one after another in physical memory and you access them using an index — a numeric value. Arrays have been around about as long as computers have existed. Even early assembler programmers used array-like structures in their programming.
Like every other language, IronPython provides arrays for you to use. However, IronPython has two native structures and several external (imported) structures that can qualify as array-like structures. In fact, unless there’s a specific reason to state otherwise, this book will simply use the term array to refer to them all. However, it’s important to understand that there are subtle differences between these array-like structures, so the following sections discuss the three common array-like structures you’ll find in IronPython.