Data Structures in Python - Part 1

June 17, 2020

Python. Beautiful, concise, simple are some words that come to mind. Python is a high-level, interpreted and dynamic programming language, created by Guido van Rossum in 1991. Python is used everywhere. It is used for general purpose programming, scripting, for the web, artificial intelligence and more. The possibilities are endless.

Python, Comic

Python for Developers

If you’re a student who is very much interested in becoming a developer, you would probably know that developer roles require a strong grasp on fundamentals, with most technical interviews for developer roles dealing with data structures. You also need to know data structures to ace the whiteboard programming and online programming rounds in recruitment processes. 🔥

When I started preparing for interviews, I found myself learning data structures as a major part of preparation. And hence, I felt that this series would give an overview of data structures to help students study for and ace interviews.

In this article, we’ll look at an overview of data structures, and then move on to learn about more data structures and their implementations in Python throughout this series! 😄

Linear Data Structures

Linear data structures store elements in a sequential manner. These are the most fundamental and widely used data structures.

  • Array/List – An array or list is a linear data structure where elements are stored in a sequential manner, numbered from 0 to n-1, where n is the size of the array. The array elements can be accessed using their index.
  • Stacks – A stack is a linear data structure that stores data in a Last In, First Out (LIFO) manner.
  • Queues – A data structure that stores data in a First In, First Out (FIFO) manner.
  • Linked Lists – A linear data structure that stores elements sequentially but cannot be accessed directly using an index. It consists of links to the next item, along with the data.

Non-Linear Data Structures

Non-Linear data structures are more complex data structures, that are not sequential in manner.

  • Trees – Trees store data in a tree-like manner. They consist of a root, which contains the data and links to children nodes. The children nodes may in turn contain more children. They are the building blocks of many other Data Structures.
  • Heaps – A heap is a tree, which is used as a priority queue. There are max-heaps, and min-heaps that contain the maximum value and the minimum value at the root node, respectively.
  • Hash Tables – Hash Tables are data structures that contain key-value pairs. They use the concept of hashing to determine the keys in the tables. Usually used for quick access of values.
  • Graphs – Graphs are complex data structures that implement a collection of nodes, connected together by vertices.

Python Collections and In-Built Data Structures

  • Tuples – They are sequential data structures, that are similar to lists, but they’re immutable.
  • Dictionary – Dictionaries are python-specific data structures that are similar to hashtables, and are used for quick access of values.
  • Sets – A collection of unordered distinct elements, that have quick access time.
  • Collections – Collections are a group of optimized implementations for data structures like dictionaries, maps, tuples, queues.

Now that we have an overview of data structures, let’s delve into the nuances of each of them in the upcoming articles of the series. Here are some resources to get you started with interview and programming preparation.

Choose a Platform

There are numerous platforms like LeetCode, HackerRank, InterviewBit, TopCoder, HackerEarth, CodeChef, CodeForces, SPOJ, etc. to learn programming. Out of these, after a lot of trial and error I felt that a combination of HackerRank and LeetCode worked really well for preparing for interviews.


HackerRank is amazing because it has customized tracks for each programming language, and one each for data structures and algorithms. There are also customized filters for each DS type like Stack, Queue, etc.


LeetCode is an excellent website for company-specific preparation. If you pay for LeetCode Premium, you get company-specific questions. This is great for preparing for companies like FaceBook, Microsoft, NetFlix, Amazon, Apple, Google, etc. They also have contests and real-time mock interviews that boost your confidence and skills.

Implement the Data Structures from Scratch

By personal experience, implementing the data structures from scratch helps a lot. It helps you to understand the data structure in detail and helps in debugging, in case you run into any errors. Python offers in-build implementation for many data structures, but it is better to learn how to implement it at least once.

Check out these resources

To wrap up, keep programming every day! Stay tuned for this amazing series of articles to kick start your learning and strengthen your fundamentals of data structures!

This article was contributed by a student member of Section's Engineering Education Program. Please report any errors or innaccuracies to