AI Hints
Home›DSA in Python Tutorial›Getting Started
DSA in Python · Lesson 1 of 132

What Is a Data Structure?

A way to organise data.

⏱ 2 min read▶ Video at 0:00🎓 Free
Watch this lesson in the DSA in Python courseWatch on YouTube ↗Full DSA in Python course

A data structure is simply a way to organise data, so that you can use it easily. You already use them every day. A shopping list, a stack of plates, a queue at the shop, a family tree. Each one keeps things in a particular order, for a particular job.

What Is a Data Structure?
From the video: What Is a Data Structure?
  • A way to organise data
  • A list, a stack, a queue
  • Each has a job

Everyday data structures

A shopping list keeps items in order, and you can add more at the end. That's like a Python list. A stack of plates only lets you take the top one. A queue at the shop serves whoever came first. And a phone book lets you jump straight to a name. That's like a dictionary.

Shopping lista list
Stack of platesa stack
Queue at a shopa queue
Phone booka dictionary

You already use them

Here are three structures that come with Python. A list keeps things in order. A dictionary connects keys to values, like names to phone numbers. And a set holds unique items, so duplicates disappear. Run it. Notice the set only kept one copy of red.

structures.pypython
shopping = ["milk", "eggs", "bread"]
phone = {"Priya": "0712", "Sam": "0788"}
colours = {"red", "blue", "red", "green"}

print(shopping[0])
print(phone["Sam"])
print(len(colours), "unique colours")
Output
milk
0788
3 unique colours

Summary

A data structure is a way to organise data for a job. Lists, dictionaries, and sets are three you already know. Next, what an algorithm is.

Key takeaways
  • Organise data for a job
  • list, dict, set
  • Each is good at something
Next up: What Is an Algorithm? — steps to solve a problem