Sitemap

Data Structures in Python: The Building Blocks of Programming

4 min readJun 26, 2026

--

“Before solving complex problems, we need to know how to organize data efficiently.”

Press enter or click to view image in full size

When I started learning Python, I realized that writing code is only half the journey. The other half is learning how to organize data so that programs become faster, cleaner, and easier to manage.

That’s where Data Structures come in.

In this blog, I’ll explain what data structures are, why they matter, and the most common data structures you’ll use in Python.

What is a Data Structure?

A data structure is simply a way of storing and organizing data so it can be used efficiently.

Think about your room.

  • Clothes go in the wardrobe.
  • Books go on a bookshelf.
  • Food goes in the refrigerator.

You organize things because it’s easier to find and use them later.

Computers do exactly the same thing with data.

Different types of data require different ways of organizing them.

Why Are Data Structures Important?

Imagine searching for one contact in a phone book.

Would you rather:

  • Search page by page?
  • Or use an organized alphabetical list?

The organized method is much faster.

Good data structures help us:

  • Store data efficiently
  • Search quickly
  • Insert new data easily
  • Delete unnecessary data
  • Improve program performance

In programming, choosing the right data structure can make a huge difference.

Press enter or click to view image in full size

Common Data Structures in Python

Python already provides several built-in data structures.

Let’s explore them one by one.

1. List

A List stores multiple items in order.

fruits = ["Apple", "Banana", "Orange"]
print(fruits)

Output

['Apple', 'Banana', 'Orange']

Features

  • Ordered
  • Mutable (can be changed)
  • Allows duplicate values

Example:

fruits.append("Mango")
print(fruits)

Output

['Apple', 'Banana', 'Orange', 'Mango']

Use lists when you need an ordered collection that changes over time.

2. Tuple

A Tuple is similar to a list, but it cannot be changed after creation.

colors = ("Red", "Green", "Blue")
print(colors)
OUTPUT:
('Red', 'Green', 'Blue')

Features

  • Ordered
  • Immutable
  • Allows duplicates

Tuples are useful when data should remain constant.

Example:

Coordinates

location = (17.3850, 78.4867)

3. Set

A Set stores unique values.

numbers = {1,2,3,4,4,5}
print(numbers)

output

{1,2,3,4,5}

Notice how duplicate values disappear automatically.

Features

  • Unordered
  • Mutable
  • No duplicates

Sets are useful when uniqueness matters.

Get Siddarth Battu’s stories in your inbox

Join Medium for free to get updates from this writer.

Example

Finding unique names.

4. Dictionary

A Dictionary stores data as key-value pairs.

student = {
"name": "John",
"age": 20,
"course": "Python"
}
print(student)

Output

{
'name':'John',
'age':20,
'course':'Python'
}

Access a value

print(student["name"])

Output

John

Features

  • Key-value storage
  • Fast lookup
  • Mutable

Dictionaries are one of the most powerful data structures in Python.

Visual Representation

Imagine organizing student information.

Dictionary
Student↓{
Name → Alice
Age → 21
Course→ Python
}

Lists look like

Shopping List
↓Milk
Bread
Eggs
Rice

Sets

Unique IDs
↓101
102
103
104

Tuples

Coordinates
↓(latitude, longitude)
Press enter or click to view image in full size

Choosing the Right Data Structure

Data Structure Ordered Mutable Duplicates Best Used For List✅✅✅Collections that change Tuple✅❌✅Fixed dataSet❌✅❌Unique values Dictionary✅*✅Keys are unique Fast lookups using keys

*In modern Python (3.7+), dictionaries preserve insertion order.

Real-Life Examples

List

A playlist of songs

Song 1
Song 2
Song 3

Tuple

Date of Birth

(15, August, 2004)

Set

Registered Email IDs

abc@gmail.com
xyz@gmail.com

No duplicates allowed.

Dictionary

Phone Contacts

Rahul → 9876543210
Priya → 9123456789

Time Complexity (Beginner Overview)

Although you don’t need to memorize these immediately, it’s helpful to know that different operations have different costs.

OperationListDictionarySetSearchO(n)O(1) AverageO(1) AverageInsertO(1) (append)O(1) AverageO(1) AverageDeleteO(n)O(1) AverageO(1) Average

This is why choosing the right data structure is important for writing efficient programs.

Final Thoughts

Data structures are the foundation of programming. Whether you’re building a simple calculator or a large-scale application, organizing data effectively makes your code easier to write, understand, and maintain.

As I continue my Python journey, I realize that mastering data structures is one of the best investments I can make. They not only improve problem-solving skills but also prepare me for algorithms, coding interviews, and real-world software development.

Learning Python isn’t just about syntax — it’s about learning to think like a programmer, and data structures are one of the first steps in that direction.

Hi I’m Sai Siddartha! If you found this article helpful, I’d love to hear your thoughts! Feel free to leave a comment and follow me on Medium as I continue sharing my learning journey in Python, Data Science, and AI.

Happy Coding! 🚀

#Python #PythonProgramming #ObjectOrientedProgramming #Programming #Coding #Beginners #DataAnalytics #DataScience #LearningJourney #InnomaticsResearchLabs

--

--