Glossary: Python Data Structures Welcome! This alphabetized glossary contains many of the terms in this course. This comprehensive glossary also includes additional industry-recognized terms not used in course videos. These terms are important for you to recognize when working in the industry, participating in user groups, and participating in other certificate programs. 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. Cheat Sheet: Python Data Structures Part-2 Dictionaries Package/Method Description Code Example Creating a Dictionary A dictionary is a built-in data type that represents a collection of key-value pairs. Dictionaries are enclosed in curly braces {}. Example: 1 2 dict_name = {} #Creates an empty dictionary person = { “name”: “John”, “age”: 30, “city”: “New York”} Copied! Wrap Toggled! Accessing Values You can access the values in a dictionary using their corresponding keys. Syntax: 1 Value = dict_name[“key_name”] Copied! Wrap Toggled! Example: 1 2 name = person[“name”] age = person[“age”] Copied! Wrap Toggled! Add or modify Inserts a new key-value pair into the dictionary. If the key already exists, the value will be updated; otherwise, a new entry is created. Syntax: 1 dict_name[key] = value Copied! Wrap Toggled! Example: 1 2 person[“Country”] = “USA” # A new entry will be created. person[“city”] = “Chicago” # Update the existing value for the same key Copied! Wrap Toggled! del Removes the specified key-value pair from the dictionary. Raises a KeyError if the key does not exist. Syntax: 1 del dict_name[key] Copied! Wrap Toggled! Example: 1 del person[“Country”] Copied! Wrap Toggled! update() The update() method merges the provided dictionary into the existing dictionary, adding or updating key-value pairs. Syntax: 1 dict_name.update({key: value}) Copied! Wrap Toggled! Example: 1 person.update({“Profession”: “Doctor”}) Copied! Wrap Toggled! clear() The clear() method empties the dictionary, removing all key-value pairs within it. After this operation, the dictionary is still accessible and can be used further. Syntax: 1 dict_name.clear() Copied! Wrap Toggled! Example: 1 grades.clear() Copied! Wrap Toggled! key existence You can check for the existence of a key in a dictionary using the in keyword Example: 1 2 if “name” in person: print(“Name exists in the dictionary.”) Copied! Wrap Toggled! copy() Creates a shallow copy of the dictionary. The new dictionary contains the same key-value pairs as the original, but they remain distinct objects in memory. Syntax: 1 new_dict = dict_name.copy() Copied! Wrap Toggled! Example: 1 2 new_person = person.copy() new_person = dict(person) # another way to create a copy of dictionary Copied! Wrap Toggled! keys() Retrieves all keys from the dictionary and converts them into a list. Useful for iterating or processing keys using list methods. Syntax: 1 keys_list = list(dict_name.keys()) Copied! Wrap Toggled! Example: 1 person_keys = list(person.keys()) Copied! Wrap Toggled! values() Extracts all values from the dictionary and converts them into a list. This list can be used for further processing or analysis. Syntax: 1 values_list = list(dict_name.values()) Copied! Wrap Toggled! Example: 1 person_values = list(person.values()) Copied! Wrap Toggled! items() Retrieves all key-value pairs as tuples and converts them into a list of tuples. Each tuple consists of a key and its corresponding value. Syntax: 1 items_list = list(dict_name.items()) Copied! Wrap Toggled! Example: 1 info = list(person.items()) Copied! Wrap Toggled! Sets Package/Method Description Code Example add() Elements can be added to a set using the `add()` method. Duplicates are automatically removed, as sets only store unique values. Syntax: 1 set_name.add(element) Copied! Wrap Toggled! Example: 1 fruits.add(“mango”) Copied! Wrap Toggled! clear() The `clear()` method removes all elements from the set, resulting in an empty set. It updates the set in-place. Syntax: 1 set_name.clear() Copied! Wrap Toggled! Example: 1 fruits.clear() Copied! Wrap Toggled! copy() The `copy()` method creates a shallow copy of the set. Any modifications to the copy won’t affect the original set. Syntax: 1 new_set = set_name.copy() Copied! Wrap Toggled! Example: 1 new_fruits = fruits.copy() Copied! Wrap Toggled! Defining Sets A set is an unordered collection of unique elements. Sets are enclosed in curly braces `{}`. They are useful for storing distinct values and performing set operations. Example: 1 2 3 empty_set = set() #Creating an Empty Set fruits = {“apple”, “banana”, “orange”} colors = (“orange”, “red”, “green”) Copied! Wrap Toggled! Note: These two sets will be used in the examples that follow. discard() Use the `discard()` method to remove a specific element from the set. Ignores if the element is not found. Syntax: 1 set_name.discard(element) Copied! Wrap Toggled! Example: 1 fruits.discard(“apple”) Copied! Wrap Toggled! issubset() The `issubset()` method checks if the current set is a subset of another set. It returns True if all elements of the current set are present in the other set, otherwise False. Syntax: 1 is_subset = set1.issubset(set2) Copied! Wrap Toggled! Example: 1 is_subset = fruits.issubset(colors) Copied! Wrap Toggled! issuperset() The `issuperset()` method checks if the current set is a superset of another set. It returns True if all elements of the other set are present in the current set, otherwise False. Syntax: 1 is_superset = set1.issuperset(set2) Copied! Wrap Toggled! Example: 1 is_superset = colors.issuperset(fruits) Copied! Wrap Toggled! pop() The `pop()` method removes and returns an arbitrary element from the set. It raises a `KeyError` if the set is empty. Use this method to remove elements when the order doesn’t matter. Syntax: 1 removed_element = set_name.pop() Copied! Wrap Toggled! Example: 1 removed_fruit = fruits.pop() Copied! Wrap Toggled! remove() Use the `remove()` method to remove a specific element from the set. Raises a `KeyError` if the element is not found. Syntax: 1 set_name.remove(element) Copied! Wrap Toggled! Example: 1 fruits.remove(“banana”) Copied! Wrap Toggled! Set Operations Perform various operations on sets: `union`, `intersection`, `difference`, `symmetric difference`. Syntax: 1 2 3 4 union_set = set1.union(set2) intersection_set = set1.intersection(set2) difference_set = set1.difference(set2) sym_diff_set = set1.symmetric_difference(set2) Copied! Wrap Toggled! Example: 1 2 3 4 combined = fruits.union(colors) common = fruits.intersection(colors) unique_to_fruits = fruits.difference(colors) sym_diff = fruits.symmetric_difference(colors) Copied! Wrap Toggled! update() The `update()` method adds elements from another iterable into the set. It maintains the uniqueness of elements. Syntax: 1 set_name.update(iterable) Copied! Wrap Toggled! Example: 1 fruits.update([“kiwi”, “grape”]) Copied! Wrap Toggled! Python Data Structures Cheat Sheet List Package/Method Description Code Example append() The `append()` method is used to add an element to the end of a list. Syntax: 1 list_name.append(element) Copied! Wrap Toggled! Example: 1 2 fruits = [“apple”, “banana”, “orange”] fruits.append(“mango”) print(fruits) Copied! Wrap Toggled! copy() The `copy()` method is used to create a shallow copy of a list. Example 1: 1 2 3 my_list = [1, 2, 3, 4, 5] new_list = my_list.copy() print(new_list) # Output: [1, 2, 3, 4, 5] Copied! Wrap Toggled! count() The `count()` method is used to count the number of occurrences of a specific element in a list in Python. Example: 1 2 3 my_list = [1, 2, 2, 3, 4, 2, 5, 2] count = my_list.count(2) print(count) # Output: 4 Copied! Wrap Toggled! Creating a list A list is a built-in data type that represents an ordered and mutable collection of elements. Lists are enclosed in square brackets [] and elements are separated by commas. Example: 1 fruits = [“apple”, “banana”, “orange”, “mango”] Copied! Wrap Toggled! del The `del` statement is used to remove an element from list. `del` statement removes the element at the specified index. Example: 1 2 3 my_list = [10, 20, 30, 40, 50] del my_list[2] # Removes the element at index 2 print(my_list) # Output: [10, 20, 40, 50] Copied! Wrap Toggled! extend() The `extend()` method is used to add multiple elements to a list. It takes an iterable (such as another list, tuple, or string) and appends each element of the iterable to the original list. Syntax: 1 list_name.extend(iterable) Copied! Wrap Toggled! Example: 1 2 3 4 fruits = [“apple”, “banana”, “orange”] more_fruits = [“mango”, “grape”] fruits.extend(more_fruits) print(fruits) Copied! Wrap Toggled! Indexing Indexing in a list allows you to access individual elements by their position. In Python, indexing starts from 0 for the first element and goes up to `length_of_list – 1`. Example: 1 2 3 4 5 my_list = [10, 20, 30, 40, 50] print(my_list[0]) # Output: 10 (accessing the first element) print(my_list[-1]) # Output: 50 (accessing the last element using negative indexing) Copied! Wrap Toggled! insert() The `insert()` method is used to insert an element. Syntax: 1 list_name.insert(index, element) Copied! Wrap Toggled! Example: 1 2 3 my_list = [1, 2, 3, 4, 5] my_list.insert(2, 6) print(my_list) Copied! Wrap Toggled! Modifying a list You can use indexing to modify or assign new values to specific elements in the list. Example: 1 2 3 4 my_list = [10, 20, 30, 40, 50] my_list[1] = 25 # Modifying the second element print(my_list) # Output: [10, 25, 30, 40, 50] Copied! Wrap Toggled! pop() `pop()` method is another way to remove an element from a list in Python. It removes and returns the element at the specified index. If you don’t provide an index to the `pop()` method, it will remove and return the last element of the list by default Example 1: 1 2 3 4 5 6 7 my_list = [10, 20, 30, 40, 50] removed_element = my_list.pop(2) # Removes and returns the element at index 2 print(removed_element) # Output: 30 print(my_list) # Output: [10, 20, 40, 50] Copied! Wrap Toggled! Example 2: 1 2 3 4 5 6 7 my_list = [10, 20, 30, 40, 50] removed_element = my_list.pop() # Removes and returns the last element print(removed_element) # Output: 50 print(my_list) # Output: [10, 20, 30, 40] Copied! Wrap Toggled! remove() To remove an element from a list. The `remove()` method removes the first occurrence of the specified value. Example: 1 2 3 4 my_list = [10, 20, 30, 40, 50] my_list.remove(30) # Removes the element 30 print(my_list) # Output: [10, 20, 40, 50] Copied! Wrap Toggled! reverse() The `reverse()` method is used to reverse the order of elements in a list Example 1: 1 2 3 my_list = [1, 2, 3, 4, 5] my_list.reverse() print(my_list) # Output: [5, 4, 3, 2, 1] Copied! Wrap Toggled! Slicing You can use slicing to access a range of elements from a list. Syntax: 1 list_name[start:end:step] Copied! Wrap Toggled! Example: 1 2 3 4 5 6 7 8 9 10 11 12 my_list = [1, 2, 3, 4, 5] print(my_list[1:4]) # Output: [2, 3, 4] (elements from index 1 to 3) print(my_list[:3]) # Output: [1, 2, 3] (elements from the beginning up to index 2) print(my_list[2:]) # Output: [3, 4, 5] (elements from index 2 to the end) print(my_list[::2]) # Output: [1, 3, 5] (every second element) Copied! Wrap Toggled! sort() The `sort()` method is used to sort the elements of a list in ascending order. If you want to sort the list in descending order, you can pass the `reverse=True` argument to the `sort()` method. Example 1: 1 2 3 4 my_list = [5, 2, 8, 1, 9] my_list.sort() print(my_list) # Output: [1, 2, 5, 8, 9] Copied! Wrap Toggled! Example 2: 1 2 3 4 my_list = [5, 2, 8, 1, 9] my_list.sort(reverse=True) print(my_list) # Output: [9, 8, 5, 2, 1] Copied! Wrap Toggled! Tuple Package/Method Description Code Example count() The count() method for a tuple is used to count how many times a specified element appears in the tuple. Syntax: 1 tuple.count(value) Copied! Wrap Toggled! Example: 1 2 3 fruits = (“apple”, “banana”, “apple”, “orange”) print(fruits.count(“apple”)) #Counts the number of times apple is found in tuple. #Output: 2 Copied! Wrap Toggled! index() The index() method in a tuple is used to find the first occurrence of a specified value and returns its position (index). If the value is not found, it raises a ValueError. Syntax: 1 tuple.index(value) Copied! Wrap Toggled! Example: 1 2 3 fruits = (“apple”, “banana”, “orange”,”apple”) print(fruits.index(“apple”)) #Returns the index value at which apple is present. #Output: 0 Copied! Wrap Toggled! sum() The sum() function in Python can be used to calculate the sum of all elements in a tuple, provided that the elements are numeric (integers or floats). Syntax: 1 sum(tuple) Copied! Wrap Toggled! Example: 1 2 3 numbers = (10, 20, 5, 30) print(sum(numbers)) #Output: 65 Copied! Wrap Toggled! min() and max() Find the smallest (min()) or largest (max()) element in a tuple. Example: 1 2 3 4 5 numbers = (10, 20, 5, 30) print(min(numbers)) #Output: 5 print(max(numbers)) #Output: 30 Copied! Wrap Toggled! len() Get the number of elements in the tuple using len(). Syntax: 1 len(tuple) Copied! Wrap Toggled! Example: 1 2 3 fruits = (“apple”, “banana”, “orange”) print(len(fruits)) #Returns length of the tuple. #Output: 3 Copied! Wrap Toggled! © IBM Corporation. All rights reserved. Glossary: Python Basics Welcome! This alphabetized glossary contains many of the terms you’ll find within this course. This comprehensive glossary also includes additional industry-recognized terms not used in course videos. These terms are important for you to recognize when working in the industry, participating in user groups, and participating in other certificate programs. Term Definition AI AI (artificial intelligence) is the ability of a digital computer or computer-controlled robot to perform tasks commonly associated with intelligent beings. Application development Application development, or app development, is the process of planning, designing, creating, testing, and deploying a software application to perform various business operations. Arithmetic Operations Arithmetic operations are the basic calculations we make in everyday life like addition, subtraction, multiplication and division. It is also called as algebraic operations or mathematical operations. Array of numbers Set of numbers or objects that follow a pattern presented as an arrangement of rows and columns to explain multiplication. Assignment operator in Python Assignment operator is a type of Binary operator that helps in modifying the variable to its left with the use of its value to the right. The symbol used for assignment operator is “=”. Asterisk Symbol “* ” used to perform various operations in Python. Backslash A backslash is an escape character used in Python strings to indicate that the character immediately following it should be treated in a special way, such as being treated as escaped character or raw string. Boolean Denoting a system of algebraic notation used to represent logical propositions by means of the binary digits 0 (false) and 1 (true). Colon A colon is used to represent an indented block. It is also used to fetch data and index ranges or arrays. Concatenate Link (things) together in a chain or series. Data engineering Data engineers are responsible for turning raw data into information that an organization can understand and use. Their work involves blending, testing, and optimizing data from numerous sources. Data science Data Science is an interdisciplinary field that focuses on extracting knowledge from data sets which are typically huge in amount. The field encompasses analysis, preparing data for analysis, and presenting findings to inform high-level decisions in an organization. Data type Data type refers to the type of value a variable has and what type of mathematical, relational or logical operations can be applied without causing an error. Double quote Symbol “ “ used to represent strings in Python. Escape sequence An escape sequence is two or more characters that often begin with an escape character that tell the computer to perform a function or command. Expression An expression is a combination of operators and operands that is interpreted to produce some other value. Float Python float () function is used to return a floating-point number from a number or a string representation of a numeric value. Forward slash Symbol “/“ used to perform various operations in Python Foundational Denoting an underlying basis or principle; fundamental. 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. Integer An integer is the number zero (0), a positive natural number (1, 2, 3, and so on) or a negative integer with a minus sign (−1, −2, −3, and so on.) Manipulate Is the process of modifying a string or creating a new string by making changes to existing strings. Mathematical conventions A mathematical convention is a fact, name, notation, or usage which is generally agreed upon by mathematicians. Mathematical expressions Expressions in math are mathematical statements that have a minimum of two terms containing numbers or variables, or both, connected by an operator in between. Mathematical operations The mathematical “operation” refers to calculating a value using operands and a math operator. Negative indexing Allows you to access elements of a sequence (such as a list, a string, or a tuple) from the end, using negative numbers as indexes. Operands The quantity on which an operation is to be done. Operators in Python Operators are used to perform operations on variables and values. Parentheses Parentheses is used to call an object. Replicate To make an exact copy of. Sequence A sequence is formally defined as a function whose domain is an interval of integers. Single quote Symbol ‘ ‘ used to represent strings in python. Slicing in Python Slicing is used to return a portion from defined list. Special characters A special character is one that is not considered a number or letter. Symbols, accent marks, and punctuation marks are considered special characters. Stride value Stride is the number of bytes from one row of pixels in memory to the next row of pixels in memory. Strings In Python, Strings are arrays of bytes representing Unicode characters. Substring A substring is a sequence of characters that are part of an original string. Type casting The process of converting one data type to another data type is called Typecasting or Type Coercion or Type Conversion. Types in Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Variables Variables are containers for storing data values.