TN Online TestSamacheer Kalvi practice

Lists, Tuples, Sets and Dictionary in Python

This chapter explores Python's four built-in collection data types: lists, tuples, sets, and dictionaries. It explains how to create, access, manipulate, and delete elements within these structures, highlighting their unique characteristics such as mutability, ordering, uniqueness, and key-value mapping to manage complex data structures efficiently.

Study this chapter

Book Back Questions12 textbook MCQs · solved Additional MCQs15 extra MCQs · solved Practice TestInteractive · instant score Book Back TestTest yourself on the textbook set Additional MCQ TestTest yourself on the extra set Study NotesConcepts & methods Formula SheetAll key formulas

About Lists, Tuples, Sets and Dictionary

Medium ~120 min study

In computer science, managing collections of related values is fundamental to building useful applications. Python addresses this need by providing four powerful built-in collection data types: lists, tuples, sets, and dictionaries. While simple variables store single values, these data structures allow programmers to bundle multiple items together under a single identifier, offering robust mechanisms for indexing, searching, and organizing complex datasets.

The key to mastering these collections lies in understanding how they differ in terms of mutability, ordering, and duplicate handling. Lists represent ordered, changeable sequences, whereas tuples provide faster, immutable alternatives for read-only data. Sets implement mathematical set operations while automatically filtering out duplicates, and dictionaries map unique keys to values for lightning-fast lookups. Together, these structures form the backbone of clean, expressive, and optimized Python programming.

For students preparing for examinations, this chapter is a critical cornerstone of both theoretical and practical assessments. Questions frequently test the syntactical differences between square brackets, parentheses, and curly braces, as well as the behavior of various built-in methods like append, pop, and clear. Mastering these collections is also essential for scoring high marks in practical coding exercises, where manipulating structured data is a core requirement.

What you'll learn

Before you start

Topics covered in this chapter

Characteristics of Python Lists Lists are ordered, mutable sequences enclosed in square brackets that can store elements of various data types and allow indices for element manipulation.
Adding and Deleting List Elements Lists support adding items using append, extend, or insert functions, and deleting them via del statements, remove, or pop methods.
List Comprehensions A compact and efficient syntax in Python to generate a sequence of elements satisfying specific conditional expressions in a single line.
Tuples vs Lists Comparison Unlike mutable lists, tuples are immutable read-only sequences enclosed in parentheses, which offer faster iteration and protect data from accidental modification.
Tuple Assignment and Packing A powerful Python feature allowing a tuple of variables on the left to be assigned values evaluated on the right simultaneously.
Creating and Formatting Sets Sets are mutable, unordered collections defined with curly braces that automatically filter out duplicate values, ensuring all stored elements are unique.
Mathematical Set Operations Sets support standard mathematical operations including union, intersection, set difference, and symmetric difference using specific operators or built-in functions.
Dictionaries as Key-Value Maps An associative data structure where each case-sensitive key maps to a value, allowing highly efficient lookups, modifications, and element additions.

Lists, Tuples, Sets and Dictionary explained

Comprehensive Guide to Python Collections

Lists as Mutable Ordered Sequences

Python lists are versatile, ordered sequence data types enclosed in square brackets that group elements together. Each element occupies a specific index starting at zero, allowing direct access or traversal in reverse order using negative subscripts. Because lists are mutable, they are highly dynamic, allowing developers to perform in-place modifications using methods like append for adding single items, extend for merging lists, or insert for adding elements at custom positions. Elements can be deleted using the del statement, remove, or pop methods. Advanced concepts like list comprehensions provide a powerful, compact syntax for generating new lists that satisfy specific conditions.

Tuples as Immutable Read-Only Sequences

Tuples consist of multiple values separated by commas, conventionally enclosed in parentheses. While syntactically similar to lists, tuples are completely immutable, meaning their elements cannot be changed, appended, or deleted once defined. This architectural difference guarantees data integrity for constant records and allows the Python interpreter to process and iterate through tuples significantly faster than their mutable counterparts. Tuples are widely used in Python for advanced operations like tuple assignment, returning multiple values from a single function, and nesting tuples within other tuple structures to represent complex, tabular records cleanly.

Sets for Unordered Unique Elements

A set is a mutable but unordered collection of elements enclosed in curly braces that strictly prohibits duplicate values. If duplicate values are specified during set creation, Python automatically discards them, which is extremely useful for membership testing and clean data filtering. Sets support standard mathematical set operations. These can be executed using operators or dedicated functions: union combines all elements from both sets; intersection retrieves only common elements; difference finds elements present in the first set but not the second; and symmetric difference returns elements that are unique to each set.

Dictionaries as Key-Value Associative Maps

Dictionaries are unordered associative data structures that store elements as key-value pairs separated by colons and enclosed in curly braces. Unlike lists or tuples which are accessed via numeric indices, dictionary elements are retrieved using their unique, case-sensitive keys, which can be strings or numbers. This key-value mapping provides an incredibly fast and logical way to look up and manage complex, structured data. Programmers can easily add new values, modify existing entries by overwriting keys, and clear or delete elements using the del keyword or the clear function.

Common mistakes to avoid

Test yourself on these with the practice test, then check the worked reasoning in the solved MCQs.

Frequently asked questions

What is the main difference between a Python list and a tuple?

The fundamental difference is mutability. Lists are mutable and enclosed in square brackets, allowing you to add, change, or remove elements. Tuples are immutable and enclosed in parentheses, meaning their elements cannot be altered once defined, which also makes tuples faster to process than lists.

How do you create a tuple that contains only one element?

To create a single-element tuple, also known as a singleton, you must include a trailing comma after the element, such as (10,). If you omit the comma, Python will interpret the parentheses as a grouping operator and treat the value as a standard integer or string data type.

What happens when you add duplicate values to a set in Python?

Sets strictly store unique elements. If you attempt to include duplicate values during set creation or add them later, Python automatically removes the duplicates and retains only a single instance of the value. No error is thrown, but the duplicates will be filtered out.

How can you safely remove all elements from a list or dictionary?

You can use the clear method to delete all elements within a list or dictionary while preserving the structure itself, leaving an empty list or dictionary. This differs from the del statement, which deletes the entire variable reference and removes it completely from memory.

What are list comprehensions and why are they used?

List comprehensions provide a concise syntax for creating lists based on existing lists or ranges. They combine the processes of loop iteration and conditional testing into a single line of code, which improves readability and executes faster than traditional loop structures.

Can you use any value as a key in a Python dictionary?

Dictionary keys must be unique and case-sensitive. They can belong to any valid, immutable Python data type, such as strings, integers, or tuples. Mutable types like lists cannot be used as keys because their values can change, which would disrupt the dictionary associative mapping mechanism.

Last updated 22 August 2026

More chapters in Computer Science

View all
1 Function 2 Data Abstraction 3 Scoping 4 Algorithmic Strategies 5 Python -Variables and Operators 6 Control Structures 7 Python functions 8 Strings and String manipulation 10 Python Classes and objects 11 Database Concepts 12 Structured Query Language (SQL) 13 Python and CSV files 14 Importing C++ programs in Python. 15 Data manipulation through SQL 16 Data visualization using pyplot: line chart, pie chart and bar chart