Chapter 3
Collections and Dictionaries
IN THIS CHAPTER
Storing data in a collection
Organizing data in a dictionary
Understanding hash tables and collisions
An array can be handy when you need to store the same type of information, such as a group of integers. However, if you need to store different information, such as both integers and strings, and you aren’t sure how many items you need to store, you probably can’t use an array. Instead, you can use a collection or a dictionary.
A collection (also called a list in some languages) acts like a resizable array that can hold different data types at the same time while identifying each chunk of data with a number. A dictionary acts like a collection that identifies each chunk of data with a unique key.
The purpose of both collections and dictionaries is to make it easier to store different types of data and retrieve them again with the size and single data type restrictions of an array.
Using a Collection
A collection acts like a super array that can grow and expand without requiring any special commands. In addition, a collection can store different data types (such as integers or strings) or even other data structures, such as ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access