Hint: You can adjust the default video playback speed 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 see our video player troubleshooting guide to resolve the issue.

Mutable Data Structures: Lists and Dictionaries

Give Feedback

In this lesson, you’ll see how you could approach this data set using mutable data structures, like lists and dictionaries. When you use mutable data structures, their contents can be modified. So if you use them to hold your data, then you run the risk of messing up your data set, since it can be changed.

If you want to have a multithreaded program and do parallel processing, then using immutable data structures would allow you to not have to worry about locking the data structures because there would be no way to update them.

Comments & Discussion

senatoduro8 on July 24, 2019

I wish the data used in this tutorials is provided like it is in the asyncio tutorials.

Dan Bader RP Team on July 24, 2019

@senatoduro8: Cheers, I just added the code sample to the end of section 1 :)

senatoduro8 on July 25, 2019

Thanks Dan. This tutorial is great! It did help me learn new was to use the map, reduce and apply functions creatively.

Pygator on Jan. 18, 2020

I thought you were going to reach in and change the name to ‘Dan Bader’ :)

Tom Pollard on April 19, 2020

The reason you want to use immutable data structures is not that “you run the risk of messing up your data set, since it can be changed”, but that it lets you write code that works through side effects. Also, it’s hazardous to pass mutable data structures to other parts of your program, since changes made through one reference to that data can then affect otherwise unrelated parts of your code. I’m sure you can communicate those reasons better than I can. But, one way or the other, accidentally “messing up” your data is just a wierd thing to suggest people worry about.

jameslangbein on May 7, 2020

Actually, Tom, “accidentally messing up your data” is not a weird thing to suggest people worry about. It’s very easy to cause unintended consequences in a complex system that uses mutable data structures. Once the code-base is large enough, it can be very difficult to keep a mental model of how a piece of data or object is changing as the system affects it.

That said, there can be very good intended consequences from using mutable data structures. For instance, if you have a master set of objects of the same class, and you want to work on a subset but have any changes reflected automatically in the master set, then a mutable structure is great.

I think the main thing to keep in mind is to be intentional when choosing a data structure, choose the right one for the right reasons. This can be difficult when just starting out though.

luckjanning on June 2, 2020

Hey!!! Wich editor are you using? I use VSC but it is way over my head & I just want something more simple.

Dan Bader RP Team on June 2, 2020

I’m using an alternative Python REPL called bpython in my videos. You can learn more about it here: bpython-interpreter.org. If bpython is difficult to install I can also recommend ptpython.

confiq on July 3, 2020

pip install bpython! I’ve replace the iPython!

Become a Member to join the conversation.