Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Dictionaries and Arrays: Selecting the Ideal Data Structure (Overview)

There are a variety of ways of storing and managing data in your Python programs, and the choice of the right data structure will affect the readability of your code, ease of writing, and performance. Python has a wide variety of built-in mechanisms that meet most of your data structure needs.

This course introduces you to two types of data structures: dictionaries and arrays. There are multiple types and classes for both of these data structures and this course discusses them and provides information on how to choose the ideal one.

In this course you’ll learn about:

  • What are the advantages of using the built-in dict type
  • What are four other types of dictionaries
  • How list and tuple types are arrays
  • What are typed arrays and how can they save memory
  • How strings are arrays and what that implies
  • What are the different arrays for storing binary data
  • What are the practical uses for the different types
  • How to select the ideal data structure for your programs

This course is the first part of an ongoing series, exploring how to find the right Data Structure for your projects. The second course is Records and Sets: Selecting the Ideal Data Structure and the third part is Stacks and Queues: Selecting the Ideal Data Structure.

Download

Sample Code (.zip)

4.9 KB
Download

Course Slides (.pdf)

725.1 KB

00:00 Welcome to Selecting the Ideal Data Structure: Dictionaries and Arrays. My name is Chris and I will be your guide. In this course, you’ll learn about how common abstract data types are used in Python, with a focus on dictionaries and maps, and array structures.

00:18 Just a quick note: All the code in here was tested using Python 3.9. Almost all the concepts discussed have been here from Python’s early days, so you should be able to use it with older versions without a problem.

00:31 I’ll do my best to point out differences between versions as I go along.

00:36 There are many different ways of organizing your data when you write code. Choosing the right data structures is important. Different kinds of structures have different purposes, strengths, and weaknesses. Python being a batteries-included language means that most common data structures are provided with the language itself. And as you’ll discover in this course, there’s often multiple different structures within Python to solve the same kinds of problems.

01:02 This course is going to focus on two kinds of data structures. The first is dictionaries and the second is arrays.

01:10 Dictionaries and data maps store key-value pairs and the relationship between them. This is a way of grouping fields that are related together in the same data structure.

01:21 The creators of Python felt that this data structure was so important, they’ve included it as a built-in type called dict. Over and on top of that though, there are also other dictionaries and maps inside of the standard library.

01:34 OrderedDict, defaultdict, ChainMap, and MappingProxyType will all be covered in this course. At the end of the section on dictionaries, I’ll discuss how to choose which implementation to use and give you some further information. The second section of the course is on arrays.

01:54 An array is a continuous chunk of memory storing a series of items. Python has two built-in types, list and tuple, that are implemented as arrays.

02:05 Both of these types can take any kind of data inside of them. In addition to that, there’s a standard library called array that provides typed arrays.

02:15 If you’re looking to manipulate binary data, the bytes and bytearray types are available to help you do this. And at the end of the section on arrays, I’ll discuss how to choose between these implementations and what’s best for your situation.

02:31 That’s enough preamble! Next up, let’s dive into dictionaries.

Become a Member to join the conversation.