2026-08-25 20:12
Status:
Tags: IBM IBM Full Stack Software Developer Professional Certificate IBM Python for Data Science, AI & Development Python Programming Lanuages Programming Concepts Data Structures
PDSAD - Module 2 - Python Data Structures
==Lists and Tuples
-
Lists and Tuples:
- A list in python is declared with
[]and is a dynamic array representation that allows a user to store a large number of differently typed pieces of data together. They are dynamic, can be indexed, and basically allow for easy storage over the use of a million different variables - There is also things like 2 D lists which are basically just lists inside of lists:
[[],[],[]]and what not, which are very useful for things like grids and boards and what not, probably useful for things like matrix representation for linear algebra, either way though - There are several python methods for lists too, you can probably have something like a slice, a sort, a length, and all general things you could imagine can be done with a list
- Tuples on the other hand I do not outright know about as much, they are basically similar to lists except I do not think that they are as mutable,
- They are expressed as
thisIsATuple = (1, 2, 3, 4, 5, 6, 7, 8, 9)inside of python - A tuple might have different types similar to how a list does, and can also be accessed and indexed in the same way that you can with lists and what not
- They can also be added and concatenated similar to how strings can
- They also share a few things similar to strings and lists where they can be sliced with
tuple2[0:3]on whatever tuple it is that you want to use, basically I think these are generally things like arrays in regular programming languages - In the sense that they are able to hold different objects, and are of type tuple but are immutable as I have said before hand, so you cannot change the inner values in them
- A list in python is declared with
==Dictionaries
-
Dictionaries:
- See now these I know a decent amount about because I had to actually implement them on my own inside of my own programming language
- At least in the sense of how they work
- Basically, you take in whatever data you would want, and then you run a mathematical algorithm on it that would hash it into a numeric value, at which point, for however large your current hash-map is, say like an array size of height, you do a modulus of that amount to see what the remainder is
- At which point that remainder is where the item goes
- This creates a sort of key & pair value that you end up having, which lets you very quickly o(1), speed actually, find whatever you wanted to find
- It is also generally good to store the hash for things like strings on them so that way you can only calculate them once instead of more than once
- If you end up having a hash collision what ends up happening is you basically go to the next bucket over, and see if the key matches for whatever the key inputted was, keep in mind a bucket stores both the key and the value for the key as well which is why this works
- If you then want to delete a given item from a hash, but it would exist inside of this whole string of the next bucket over and what not, then you just delete it, create a basically tombstone bucket which you then skip over and delete the next time you resize the hash-map
- You generally want to have a very spread out hashing algorithm whenever you have use one because the more hash collisions you have, the closer to o(n) your hash-map gets
- Check My Own Github Repo About this for more information
- Anyways, python calls hash-maps dictionaries which I find strange but I get it, basically they are one of the only things you declare with
{}and go like thisdictionary = {key : value}with either or being whatever you generally want, and then there is also a few methods that you have which let you get the keys - You index a given dictionary using something like
dictionary[key]I believe but IDK, you can also add in a new value to the dictionary usingdicitonary[key] = pair, and delete withdel() - You can also get all of the keys in a dictionary using
dictionary.keys()
==Sets
-
Sets:
-
These are pretty interesting and I have actually only even come across them inside of python, and they exist inside of the python standard library as well
-
These are basically like lists in the sense that they can hold multiple items and I believe are actually mutable unlike things like tuples
-
Sets have only unique elements meaning that they can never actually hold a duplicate of an item, which makes them REALLY good for logic comparison of data between two given events
-
They also do not record element position unlike lists and tuples generally
-
They are defined using
set = {}and basically just are the same as an empty dictionary if you think about it with that kind of syntax, but they basically NEVER hold a duplicate item, even if created with one -
You can also create a set with the
set(list)command which converts a list into a set, and if the length of the two is different, then you know there are duplicates btw -
You can add things with the
a.removeora.addmethod on your set, and then you can use theinkeyword to see if there is a thing in there, basically you know how it is man -
-
-
You can use an
&in order to compare the contents of two different sets and see if they have matching data, or what matching data it is that they have -
It is helpful to think of these things as diagrams where when using the
album3 = album2 & album1and you can see what things they have in common, once again, really good for data if you really think about it
-
==Module 2 Summary
- In Python, we often use tuples to group related data together.Tuples refer to ordered and immutable collections of elements.
- Tuples are usually written as comma-separated elements in parentheses “()”.
- You can include strings, integers, and floats in tuples and access them using both positive and negative indices.
- You can perform operations such as combining, concatenating, and slicing on tuples.
- Tuples are immutable, so you need to create a new tuple to manipulate it.
- Tuples, termed nesting, can include other tuples of complex data types.
- You can access elements in a nested tuple through indexing.
- Lists in Python contain ordered collections of items that can hold elements of different types and are mutable, allowing for versatile data storage and manipulation.
- A list is an ordered sequence, represented with square brackets ”[]”.
- Lists possess mutability, rendering them akin to tuples.
- A list can contain strings, integers, and floats; you can nest lists within it.
- You can access each element in a list using both positive and negative indexing.
- Concatenating or appending a list will result in the modification of the same list.
- You can perform operations such as adding, deleting, splitting, and so forth on a list.
- You can separate elements in a list using delimiters.
- Aliasing occurs when multiple names refer to the same object.
- You can also clone a list to create another list.
- Dictionaries in Python are key-value pairs that provide a flexible way to store and retrieve data based on unique keys.
- Dictionaries consist of keys and values, both composed of string elements.
- You denote dictionaries using curly brackets.
- The keys necessitate immutability and uniqueness.
- The values may be either immutable or mutable, and they allow duplicates.
- You separate each key-value pair with a comma, and you can use color highlighting to make the key more visible.
- You can assign dictionaries to a variable.
- You use the key as an argument to retrieve the corresponding value.
- You can make additions and deletions to dictionaries.
- You can perform an operation on a dictionary to check the key, which results in a true or false output.
- You can apply methods to obtain a list of keys and values in a dictionary.
- Sets in Python are collections of unique elements, useful for tasks such as removing duplicates and performing set operations like union and intersection. Sets lack order.
- Curly brackets ”{}” are helpful for defining elements of a set.
- Sets do not contain duplicate items.
- A list passed through the set function generates a set containing unique elements.
- You use “Set Operations” to perform actions such as adding, removing, and verifying elements in a set.
- You can combine sets using the ampersand ”&” operator to obtain the common elements from both sets.
- You can use the Union function to combine two sets, including both the common and unique elements from both sets.
- The sub-set method is used to determine if two or more sets are subsets.
==Module 2 Glossary
| Term | Definition |
|---|---|
| Aliasing | Aliasing refers to giving another name to a function or a variable. |
| Ampersand | A character typically ”&” standing for the word “and.” |
| Compound elements | Compound statements contain (groups of) other statements; they affect or control the execution of those other statements in some way. |
| Delimiter | A delimiter in Python is a character or sequence of characters used to separate or mark the boundaries between elements or fields within a larger data structure, such as a string or a file. |
| Dictionaries | A dictionary in Python is a data structure that stores a collection of key-value pairs, where each key is unique and associated with a specific value. |
| Function | A function is a block of code, defining a set procedure, which is executed only when it is called. |
| Immutable | Immutable Objects are of in-built datatypes like int, float, bool, string, Unicode, and tuple. In simple words, an immutable object can’t be changed after it is created. |
| Intersection | The intersection of two sets is a new set containing only the elements that are present in both sets. |
| Keys | The keys () method in Python Dictionary, returns a view object that displays a list of all the keys in the dictionary in order of insertion using Python. |
| Lists | A list is any list of data items, separated by commas, inside square brackets. |
| Logic operations | In Python, logic operations refer to the use of logical operators such as “and,” “or,” and “not” to perform logical operations on Boolean values (True or False). |
| Mutable | Mutable objects in Python are objects whose values can be changed after they are created. These objects allow modifications such as adding, removing, or altering elements without creating a new object. |
| Nesting | A nested function is simply a function within another function and is sometimes called an “inner function”. |
| Ratings in python | Ratings in Python typically refer to a numerical or qualitative measure assigned to something to indicate its quality, performance, or value. |
| Set operations | Set operations in Python refer to mathematical operations performed on sets, which are unordered collections of unique elements. |
| Sets in python | A set is an unordered collection of unique elements. |
| Syntax | The rules that define the structure of the language for python is called its syntax. |
| Tuples | These are used store multiple items in a single variable. |
| Type casting | In python, this is converting one data type to another. |
| Variables | In python, a variable is a symbolic name or identifier used to store and manipulate data. Variables serve as containers for values, and these values can be of various data types, including numbers, strings, lists, and more. |
| Venn diagram | A Venn diagram is a graphical representation that uses overlapping circles to illustrate the relationships and commonalities between sets or groups of items. |
| Versatile data | Versatile data, in a general context, refers to data that can be used in multiple ways, is adaptable to different applications or purposes, and is not restricted to a specific use case. |

