Unit 2 - Lists and Loops Flashcards
.add()
Once a set is created, if we wanted to add an element to a set, we would use the .add() method. If the element already exists, the .add() method will not add the element to the set.
.append()
The .append() method allows us to add a new element to the end of a list or other data collection type.
.discard()
The .discard() method removes a specified element from the data collection type object. The .discard() method will not raise an error if the element does not exist in the object.
.extend()
The .extend() method takes a list (or other data collection type) as an argument and then appends (or adds) all of those elements to the end of another list or data collection.
.format() method
With the .format() method, any character value(s) within curly brackets are replaced with the objects that are passed to the .format() method.
.insert()
The .insert() method allows us to add an element to a list or other data collection type, in any position.
.pop()
The .pop() method modifies the list (or other data collection type) and returns the element that was removed.
.remove()
Use the .remove() method if we know the element of a list (or other data collection type) we wish to remove (but not the index); the .remove() method takes away the first instance that the element occurs. If the element does not exist, using this method will raise an error.
.sort()
The .sort() method arranges all of the elements in a list (or other data collection type) from the lowest to highest. If the values are strings, the result will be a list of strings in alphabetical order.
.strip()
The .strip() method is a string method that removes any spaces before the first character or after the last character.
.update()
Use the .update() method to add elements from another iterable object (data collection type) into the current iterable object. If an element exists in both objects, only one element will be updated to the combined data collection type.
.values()
The .values() method returns an object that contains the values of the dictionary as a list.
2D (Two Dimensions)
A nested list or other data collection type (iterable objects like lists, set, tuple, or dictionary) inside another iterable object is called two dimension or 2D for short. Any data collection type can contain other nested collection types as well in multiple dimensions.
Base Case
The base case is where the program no longer calls itself recursively and allows a recursive function to end.
Body of the Loop
The body of the loop represents the indented block of code that should be executed repeatedly within the loop during each loop iteration.
Data Collection Type
A data collection type is a collection of related values that are organized in a specific way so that they can be used effectively.
Debugging by Bisection
Debugging by bisection is the practice of breaking your program code into “sections” for debugging and validation purposes. This will help speed up the debugging process since you may be able to find issues within a section rather than the full program.
Definite Iteration
With definite iteration, the number of times the block of code runs should be explicitly defined when the loop actually starts. Typically, this is implemented using the for loop. The for loop has a specific start and endpoint.
Dictionary
A dictionary is like a list, but more generalized. Dictionaries store data values in key:value pairs that are changeable, meaning that we can change, add, or remove elements after the dictionary has been created. Dictionaries cannot have two elements of the same key.
Element
An element is one of the values in a list (or other data collection type); elements can also be called items.
Encapsulation
Encapsulation is an important part of programming where we try to bundle data and functions that belong to a specific topic into a single unit. We do this to restrict direct access to some parts of the function.
Flow of Execution
The order in which statements are executed is called the flow of execution. Execution always begins at the first statement of the program. Statements are executed one at a time, in order from top to bottom.
Function Definition
A function definition specifies the name of a new function and the sequence of statements that execute when the function is called.
Global Scope
Global scope means variables can be accessed throughout the entire program.