Lists and tuples are similar but have some differences, e.g. lists are mutable, while tuples are immutable. Aliasing and Cloning can be carried out with list.
I was unable to study on October 25th.
*Day 67 [October 26, 2025]
*
I need to buckle down, as I'm still lagging on day day 3 & 4 goals, "Day 3-4: Control structures (if-else, loops)", as well as day 5 (and 6) goals, "Day 5-6: Functions and modules", and Day 7 target (exercises) (Meta AI, personal communication, August 8, 2025). If I haven't covered this, I can't make progress on day 8 - 66 goals.
Goals:
As extracted from the 'Python for Software Development' textbook by Halvorsen (n.d.):
- Plotting in Python ✅
- Subplots✅
- Exercises✅
- If ... Else
- Arrays
- For Loops
- Nested
- For Loops
- While Loops
- Exercises
- Creating Functions in Python - Introduction
- Functions with multiple return values
- Exercises
- Creating Classes in Python
- The init () Function
- Exercises
- Creating Python Modules
- Exercises
Notes:
Python for Data Science, AI & Development Course (IBM) (Santarcangelo, n.d.):
Module 2: Python Data Structures
- Lists and Tuples
- Dictionaries
- Sets
Lists and Tuples
- Called Compound Data Types, so called because multiple values of different data types can be held in them, also allowing the organization and management of data collection (see also Google, 2025)
- List, sets, tuples, and dictionaries are important data structures in Python
- List operations include manipulation, indexing and sorting (MIS).
- Sets are an unordered collection. Why so?
Tuples
- Ordered sequence.
- Strings, floats and integer can be held in a tuple. Index can be used to access elements in a tuple, as well as negative index.
- They can be concatenated and sliced.
- They are immutable. Hence, to have a tuple manipulated, a new object has to be made, e.g.
tuple1 = ("FLY", 43, 2.3)
tuple2 = tuple1
tuple1= ("chcijeb",23)
print(tuple2)
Outputs:
("FLY", 43, 2.3)
tuple1 = ("FLY", 43, 2.3)
tuple2 = tuple1
tuple1= ("chcijeb",23)
tuple2 = tuple1 #note here that we had to "reassign" the tuple
print(tuple2)
Outputs:
tuple1= ("chcijeb",23)
- Tuples can also be nested.
Lists
- Ordered sequence. Why?
- Mutable
- Can contain floats, strings and integers
- Can be nested with other lists, tuples and data structures
- Indexing is applicable here, as well as slicing and contacenating
- split() method is used to transform a string into a list separating the items differentiated by space into elements of the list, and if we had a delimiter, the delimiter serves as the means of separation for the characters of a string, e.g.:
"Fly up".split()
Outputs:
["Fly", "up"]
and,
"F,l,y, u,p".split(",")
Outputs:
['F', 'l', 'y', ' u', 'p']
- Aliasing (referencing of same list, that is, one (same) object is referenced by multiple names) and Cloning (creating a new copy of the original list) can be done with list.
- Changing the element of one list affects the other in Aliasing but not so in Cloning (which doesn't effect the changes in the other). Example,
Aliasing:
First = ["Arsenal", 1, 1.0]
Second = First
print(First)
print(Second)
Second [1] = "Chelsea"
print(First)
print(Second)
Outputs:
['Arsenal', 1, 1.0]
['Arsenal', 1, 1.0]
['Arsenal', 'Chelsea', 1.0]
['Arsenal', 'Chelsea', 1.0]
Cloning:
First = ["Arsenal", 1, 1.0]
Second = First[:] #note the syntax here
print(First)
print(Second)
Second [1] = "Chelsea"
print(First)
print(Second)
Outputs:
['Arsenal', 1, 1.0]
['Arsenal', 1, 1.0]
['Arsenal', 1, 1.0]
['Arsenal', 'Chelsea', 1.0]
Summary:
Lists and tuples are similar but have some differences, e.g. lists are mutable, while tuples are immutable. Aliasing and Cloning can be carried out with list.
References:
Google. (2025). Google Search with AI. [Large language model]. https://www.google.com/search?q=compound+data+types+in+python&sca_esv=e56551571a6f13fc&sxsrf=AE3TifN4D5tW7DPCYkIdMEQQ-T-IXi02Gw%3A1761344018252&ei=Evr7aOqRD9qwhbIP6OfVOQ&oq=Compound+Data+Types&gs_lp=Egxnd3Mtd2l6LXNlcnAiE0NvbXBvdW5kIERhdGEgVHlwZXMqAggAMgoQABiwAxjWBBhHMgoQABiwAxjWBBhHMgoQABiwAxjWBBhHMgoQABiwAxjWBBhHMgoQABiwAxjWBBhHMgoQABiwAxjWBBhHMgoQABiwAxjWBBhHMgoQABiwAxjWBBhHSIsIUABYAHABeAGQAQCYAQCgAQCqAQC4AQHIAQCYAgGgAgyYAwCIBgGQBgiSBwExoAcAsgcAuAcAwgcDMy0xyAcJ&sclient=gws-wiz-serp
Halvorsen, H. (n.d.). Python. https://halvorsen.blog/documents/programming/python/python.php#python4
Santarcangelo, J. (n.d.). Python for data science, AI & development [MOOC]. Coursera. https://coursera.org/learn/python-for-applied-data-science-ai
Top comments (0)