Mark As Completed Discussion

As a senior engineer, you are aware that data structures are the fundamental building blocks of computer science. Especially, when we talk about building datastores from scratch, understanding how data structures work could not be more crucial. Here we'll be discussing simple built-in data structures in Python including lists (arrays), dictionaries (hashmaps), and sets.

We initialize a List arr, a Dictionary d corresponding to stock symbols to company names, and a Set s. The thing to take note of at this stage is that lists (a type of sequence) hold the order of insertion, dictionaries and sets (types of collection) do not.

Adding elements to these data structures, arr.append(6) adds the integer ‘6’ to the end of our list. When we add a key-value pair to our dictionary d['AMZN'] = 'Amazon', the new entry gets placed arbitrarily within the dictionary because, unlike lists, dictionaries are unordered which means they do not record element position. Sets function similarly to dictionaries and do not maintain element order, hence adding 'AMZN' to our set s places it arbitrarily.

This might seem simple, but this is the cornerstone of understanding how to implement more complex structures that underpin datastores such as trees, graphs, and different kinds of indexes.

PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment