Python Data Structures- Explained

Python Data Structures- Explained: A blog that shows data structures through python programs.

To get a better understanding of the data structures, I decided to implement them in Python. This series of posts will explore the strengths and weaknesses of each structure as well as give examples on when to use each one.


If you have any questions, feel free to ask! I am always open to improvements so please leave a comment if you have any feedback!

Python Data Structures- Explained: A blog that shows data structures through python programs.

1. Linear Data Structures- List, Stack, Queue, Linked List

2. Non Linear Data Structures- Tree, Binary Tree, Graph

3. Searching- Sequential Search, Binary Search

4. Sorting- Bubble Sort, Merge Sort, Selection Sort

Python Data Structures- Explained: A blog that shows data structures through python programs.

I’ve been learning python for a couple of months now, and I’ve found it to be a pretty interesting language. One thing that stood out to me was how easy it was to implement some basic data structures compared to Java. For example, here is some code for inserting a new node into a linked list in Java:

Link :

You are already aware that Python is a general purpose programming language. It has a wide area of applications and is used for many different purposes. One of the most important aspects of Python is Object Oriented Programming (OOP). Today, I will try to cover most of the data structures in Python using OOP concepts and also try to provide you with some very basic programs which you can execute on your own and try different operations on them. But before we begin, let’s get an idea of what a data structure is.

Data Structure:

According to Wikipedia, in computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. Data structures can implement one or more particular abstract data types (ADT), which specify the operations that can be performed on a data structure and the computational complexity of those operations.

Let’s start with defining some basic terms:

Data structure: A data structure is a group of data elements grouped together under one name. These data elements, known as members , can have different types and different lengths. Data

This blog is about python data structures. I have written the following blogs based on the common problems we face in competitive coding. The programs given below are the solutions for the problems. I have tried to explain each and every step for you to understand it easily.

The common data structures used in competitive programming are: Arrays, Strings, Linked lists, Stack and Queues, Trees, Heaps, Graphs and Sets/Hash table.

I will be writing blogs on all these topics which will include the codes and their explanation.

When it comes to data structures in Python, there are two main types: lists and dictionaries. Lists are essential to programming. It is what we use to store a series of items. Let’s break down the list.

A list is an ordered collection of items, typically numbers or strings. The elements within a list can be accessed using an index. For example, if we had a list named favorite_movies and it contained movie names, we could access one element at a time:

favorite_movies = [“Remember the Titans”, “The Blind Side”]


Output: Remember the Titans

Dictionaries are another type of data structure that contains key-value pairs. To access the values in a dictionary, you must use the key associated with it.

For example, if we have a dictionary named favorite_actors that contained actor names as keys and their movies they starred in as values we could use the following code to access them:

favorite_actors = {‘Denzel Washington’: ‘Remember the Titans’, ‘Sandra Bullock’: ‘The Blind Side’}

print(favorite_actors[‘Denzel Washington’])


1. Arrays

Arrays in Python: Arrays are used to store multiple values in one single variable

Leave a Reply

Your email address will not be published.