Skip to main content
Practice

Data Structures for Systematic Data Management

Data Structures refer to the theories and methodologies used to efficiently store, organize, and manage data.

The list, tuple, dictionary, and set you learned in the previous chapters are representative examples of data structures used to manage data systematically in programming.

Difference between Data Type and Data Structure: Data Type signifies the kind of data, whereas Data Structure signifies the method of storing and organizing data.

Let's briefly review the main data structures in Python that we learned in previous lessons.


List

A list stores multiple items in a sequential order.

List Example
numbers = [1, 2, 3, 4, 5]

# Add an item to the list
numbers.append(6)

# Prints [1, 2, 3, 4, 5, 6]
print("numbers:", numbers)

In other programming languages, structures that store multiple items like lists are often referred to as arrays.

Strictly speaking, an array has a fixed size, whereas a list is dynamic in size.


Tuple

A tuple is similar to a list, but once created, its values cannot be changed, making it an immutable data structure.

Tuple Example
coordinates = (10, 20)

# Prints (10, 20)
print("coordinates:", coordinates)

Tuples ensure data immutability, which can enhance the stability of a program.


Dictionary

A dictionary is a data structure that stores data in key-value pairs.

You can quickly retrieve a value using its key.

Dictionary Example
person = {"name": "Alice", "age": 25}

# Prints "Alice"
print("person[\"name\"]:", person["name"])

Set

A set is a collection of unique elements, used when the order of elements is not important.

Sets allow for fast performance of union, intersection, and difference operations.

Set Example
unique_numbers = {1, 2, 3, 4, 4, 5}

# Prints {1, 2, 3, 4, 5} (duplicates removed)
print("unique_numbers:", unique_numbers)

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.