Unit III: Data Structures and Modules

Table of Contents

1. Lists

A List is an ordered, mutable collection of items that can be of different data types.


2. Tuples

A Tuple is an ordered, immutable sequence of items. Once created, its elements cannot be changed.


3. Sets

A Set is an unordered collection of unique elements.


4. Dictionaries

A Dictionary is a mapping of unique keys to values.


5. Python Modules

A Module is a file containing Python definitions and statements that can be reused in other programs.


6. String Manipulation

Advanced string handling techniques are vital for data processing.

Exam Tips: Data Structure Comparison

Structure Ordered? Mutable? Duplicates?
List Yes Yes Allowed
Tuple Yes No Allowed
Set No Yes No
Dictionary No (pre-3.7) Yes Keys must be unique

Common Mistakes


Frequently Asked Questions

Q1: When should I use a Tuple instead of a List?
Use a tuple when you have data that should not change throughout the program (e.g., coordinates, constant settings) to ensure data integrity.

Q2: How do I remove duplicates from a list?
The easiest way is to convert the list to a set using set(my_list) and then back to a list, as sets automatically handle unique elements.