The Art of Flexibility: Mixing Data Types in Python’s Lists and Dictionaries

Why We Can Have Different Data Types In A Single Python List/Dict?

Konstantin Borimechkov
3 min readApr 25, 2024

Coming from Java to Python, way back, I was really amazed at the fact that in Python you can have lists, tuples or dictionaries with different data types inside.. 🤯

Where Can We Use Them?

Well, whenever you see fit.. 🤷‍♂ For me, since I am mostly working on trading bots and rarely do I work on API projects, which use Python, I use them in defining defining signals and strategies, keeping the order books data, and etc.. 👇

Now, How Does Python Allow For Such Phenomenon ??

To understand this, our best starting point is to understand what are and the difference between container and flat sequences 👀

Container Sequence

A container sequence can store references to items of different types.

Flexibility is the number 1 advantage of this type of sequences.

--

--

Konstantin Borimechkov

Writing Code For a Living 🚀 | Software Engineer @ Tide | Writing Blogs About Python & CS