Python Data Structures: Lists, Tuples, Dictionaries, Sets

📘 Python for Data Science 👁 67 views 📅 Nov 14, 2025
⏱ Estimated reading time: 2 min

Python provides four built-in and highly versatile data structures: List, Tuple, Dictionary, and Set. These structures are used to store collections of data and support efficient operations such as insertion, deletion, searching, and iteration. Together, they form the foundation of Python programming and are used in almost every application—from data analysis to web development.


List in Python

A List is an ordered, mutable (changeable) collection of items. It can store elements of different data types.

✴ Features:

  • Ordered (maintains insertion order)

  • Mutable

  • Allows duplicate values

  • Indexed (supports indexing & slicing)

✴ Example:

fruits = ["apple", "banana", "mango"] fruits[1] = "orange" # modifying list

✴ Common Operations:

OperationExampleOutput
Appendfruits.append("grape")Adds item
Insertfruits.insert(1,"kiwi")Adds at index
Removefruits.remove("apple")Deletes
Slicingfruits[1:3]Sublist

✴ Use Cases:

  • Dynamic data

  • Data that needs frequent updates


Tuple in Python

A Tuple is an ordered, immutable collection of items.

✴ Features:

  • Ordered

  • Immutable (values cannot be changed)

  • Allows duplicates

  • Faster than lists

✴ Example:

colors = ("red", "green", "blue")

✴ Advantages:

  • Data protection (immutable)

  • Useful in fixed data (coordinates, constant values)

✴ Example Operations:

colors.count("red") colors.index("green")

Dictionary in Python

A Dictionary stores data as key–value pairs. It is an unordered, mutable, and highly optimized data structure.

✴ Features:

  • Stores data in key:value format

  • Keys must be unique

  • Mutable

  • Fast lookup

✴ Example:

student = { "name": "Rahul", "age": 21, "course": "BCA" }

✴ Common Operations:

OperationExample
Accessstudent["name"]
Addstudent["grade"] = "A"
Updatestudent["age"] = 22
Deletedel student["course"]
Get keysstudent.keys()

✴ Use Cases:

  • JSON data

  • Data modeling

  • Key-value storage systems


Set in Python

A Set is an unordered collection of unique items.

✴ Features:

  • No duplicate values

  • Unordered

  • Mutable

  • Supports mathematical set operations

✴ Example:

numbers = {1, 2, 3, 3, 4} print(numbers) # Output: {1, 2, 3, 4}

✴ Common Set Operations:

A = {1, 2, 3} B = {3, 4, 5} A.union(B) # {1, 2, 3, 4, 5} A.intersection(B) # {3} A.difference(B) # {1, 2}

✴ Use Cases:

  • Removing duplicates

  • Membership testing (very fast)

  • Mathematical operations


Comparison of Python Data Structures

FeatureListTupleDictionarySet
Ordered(Python 3.7+) ✔
Mutable
Allows DuplicatesKeys ❌, Values ✔
IndexingKey-based
Use CaseDynamic dataFixed dataKey-value mappingUnique items/set ops

Conclusion

Python’s built-in data structures—Lists, Tuples, Dictionaries, Sets—form the backbone of efficient data handling.

  • Lists are ideal for dynamic and frequently updated data.

  • Tuples are perfect when data must remain constant.

  • Dictionaries provide fast, structured storage using key-value pairs.

  • Sets are best for uniqueness and mathematical operations.

A good understanding of these structures is essential for writing optimized and readable Python programs.


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes