Fundamentals of Computer Programming
( ITEd1322
(ITEd1322) )
UNIT 3: PYTHON DATA STRUCTURES
Prepared by Course Instructor
Competency-Based Objectives & Learning Outcomes
• The student is able to describe, organize, manipulate, and retrieve data
efficiently using Python’s built-in data structures for different computational
purposes.
» Upon successful completion of this unit, students will be able to:
» Describe Python’s basic data structures (lists, strings, dictionaries, tuples, sets).
» Create and manipulate lists, strings, and dictionaries.
» Differentiate between mutable and immutable data structures.
» Apply operations on data structures to solve simple problems.
Fundamentals of Computer Programming using Python 4/14/2026 103
Introduction
• Data structures as systematic ways of organizing and storing data to enable
efficient access, processing, and use within a program.
• They explore Python’s built-in data structures, such as lists, strings,
dictionaries, tuples, and sets, and understand how these structures extend
beyond basic numeric data types like integers and floating-point numbers.
Fundamentals of Computer Programming using Python 4/14/2026 104
Lists
• It is an ordered collection of items.
• It is created by placing all of the items (its elements) inside a square bracket [ ],
separated by commas.
• It is a mutable (elements can be added, changed, or removed).
• It can have any number of items, and they may be of different types (integer,
float, string, etc.), even another list as a nested list.
Fundamentals of Computer Programming using Python 4/14/2026 105
Lists … (2) … Creating Different Lists
• Created lists of various types.
• When lists are created, a series of memory locations will be allocated for the elements of the list,
as shown below with the mixedLst list whose elements can be accessed using index position.
Fundamentals of Computer Programming using Python 4/14/2026 106
Lists … (3) … Accessing List Elements
• List elements are basically accessed using indexes, first element is at index 0.
• Negative index starts at -1 (last element).
• We can also use slicing of range of values and iteration (loops) to access list
elements.
• Some common methods of accessing list elements.
Fundamentals of Computer Programming using Python 4/14/2026 107
Lists … (4) … Accessing List Elements
• …
Fundamentals of Computer Programming using Python 4/14/2026 108
Lists … (5) … Updating List Elements
• Since lists are mutable, we can change their elements by assigning new values
to specific indices.
• New elements can also be added at the end of the list from other lists as well.
• We can also delete a particular element or the whole list.
• Example:
» The demonstration of these operations are shown in NEXT SLIDE.
Fundamentals of Computer Programming using Python 4/14/2026 109
Lists … (6) … Updating List Elements
• …
Fundamentals of Computer Programming using Python 4/14/2026 110
Lists … (7) … Updating List Elements
• …
Fundamentals of Computer Programming using Python 4/14/2026 111
Lists … (8) … Updating List Elements
• A methods and functions like insert, append, pop, del, and clear are called
built-in or pre-defined which designed for a particular task.
• Common List Functions
Fundamentals of Computer Programming using Python 4/14/2026 112
Lists … (9) … Updating List Elements
• Activity
Fundamentals of Computer Programming using Python 4/14/2026 113
Tuples
• It is an ordered, immutable collection of elements.
• It is defined using parentheses ( ).
• It can store mixed data types (integers, strings, floats, etc.) and duplicated elements.
• However, tuples’ elements cannot be changed (immutable) once created and hence are
faster than lists.
• Tuples are more preferable when we want read-only data (like coordinates, days of the
week) and when we want to use them as dictionary keys or set elements (lists cannot
be keys).
Fundamentals of Computer Programming using Python 4/14/2026 114
Tuples … (2) … Creating Tuples
• Created tuples of various types.
Fundamentals of Computer Programming using Python 4/14/2026 115
Tuples … (3) … Accessing Tuple Elements and Tuple Operations
• Tuple elements can basically be accessed through indexing, slicing, and iteration.
• Furthermore, tuples support operations like concatenation, repetition, packing, and
unpacking of elements.
• Concatenation of two tuples using the plus + operator creates a new combined tuple.
• The elements of a tuple can be easily duplicated using the * operator.
• Packing allows us to put multiple values into a single tuple variable, while the
unpacking operation extracts tuple elements into separate variables.
• The NEXT SLIDE program shows accessing a tuple’s elements and apply some tuple
operations.
Fundamentals of Computer Programming using Python 4/14/2026 116
Tuples … (4) … Accessing Tuple Elements and Tuple Operations
• …
Fundamentals of Computer Programming using Python 4/14/2026 117
Tuples … (5) … List of Nested Tuples
• Also, list of nested tuples that can be unpacked inside a loop.
• Example:
» Write a Python program with three courses tuple records are defined, course itself
being a list. The loop unpacks those tuples values using separate variables.
Fundamentals of Computer Programming using Python 4/14/2026 118
Strings
• It is an ordered sequence of characters enclosed in single quotes ' ', double
quotes " ", or triple quotes ' ' ' ' ' ' / """ """.
• It is an immutable (cannot be changed once created).
• Concatenation, repetition and formatting are used to build strings.
• It also supports indexing, slicing, iteration, and many other built-in methods.
Fundamentals of Computer Programming using Python 4/14/2026 119
Strings … (2)
• Example 1: Creating String
• Example 2: Accessing String Characters
Fundamentals of Computer Programming using Python 4/14/2026 120
Strings … (3) … String Operations and Methods
• …
Fundamentals of Computer Programming using Python 4/14/2026 121
Strings … (4) … Summary of Common Python String Methods
• …
Fundamentals of Computer Programming using Python 4/14/2026 122
Strings … (5) … Summary of Common Python String Methods
• …
Fundamentals of Computer Programming using Python 4/14/2026 123
Strings … (6)
• Activity
Fundamentals of Computer Programming using Python 4/14/2026 124
Sets
• It is an unordered, mutable collection of unique elements.
• It is defined or created using curly braces { } or the set( ) constructor.
• A constructor is a special method (block of code) for initializing the state of
program objects.
• Since sets are unordered, we cannot use indexing like set [0] to access
elements. We would rather access the elements using loops.
• Set elements can be added and removed from the list easily using different
methods.
Fundamentals of Computer Programming using Python 4/14/2026 125
Sets … (2) … Create, Access, Modify and Remove
• …
Fundamentals of Computer Programming using Python 4/14/2026 126
Sets … (3) … Set Operations
• A set support common set operations such as intersection, union and symmetry.
• Example:
Fundamentals of Computer Programming using Python 4/14/2026 127
Dictionary
• In python , it is a built-in data structure that stores data in key–value pairs.
• The key and value pairs are separated by a colon:.
• It is mutable, unordered, and allows for fast lookups based on keys.
• Its values are accessed using keys.
• Example:
» The NEXT SLIDE program create, access the values through the keys, add new
pairs, modify and remove values from the dictionary.
Fundamentals of Computer Programming using Python 4/14/2026 128
Dictionary … (2)
• …
Fundamentals of Computer Programming using Python 4/14/2026 129
Dictionary … (3)
• One of the powerful things about Python dictionaries is that they can be
combined with other data structures like lists, tuples, sets, and even other
dictionaries.
• This allows you to create flexible and complex data models.
• Example:
» The NEXT SLIDE program contains a combined List of dictionaries and
Dictionary of dictionaries.
Fundamentals of Computer Programming using Python 4/14/2026 130
Dictionary … (4) … List of Dictionary
• …
Fundamentals of Computer Programming using Python 4/14/2026 131
Dictionary … (5) … Nested Dictionary
• …
Fundamentals of Computer Programming using Python 4/14/2026 132
Dictionary … (6)
• Activity
Fundamentals of Computer Programming using Python 4/14/2026 133
Unit Summary
• …
Fundamentals of Computer Programming using Python 4/14/2026 134
Unit Review Questions
• …
Fundamentals of Computer Programming using Python 4/14/2026 135