Unit 2 - Lists and Loops Flashcards

1
Q

.add()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

.append()

A

The .append() method allows us to add a new element to the end of a list or other data collection type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

.discard()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

.extend()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

.format() method

A

With the .format() method, any character value(s) within curly brackets are replaced with the objects that are passed to the .format() method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

.insert()

A

The .insert() method allows us to add an element to a list or other data collection type, in any position.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

.pop()

A

The .pop() method modifies the list (or other data collection type) and returns the element that was removed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

.remove()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

.sort()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

.strip()

A

The .strip() method is a string method that removes any spaces before the first character or after the last character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

.update()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

.values()

A

The .values() method returns an object that contains the values of the dictionary as a list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

2D (Two Dimensions)

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Base Case

A

The base case is where the program no longer calls itself recursively and allows a recursive function to end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Body of the Loop

A

The body of the loop represents the indented block of code that should be executed repeatedly within the loop during each loop iteration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Data Collection Type

A

A data collection type is a collection of related values that are organized in a specific way so that they can be used effectively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Debugging by Bisection

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Definite Iteration

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Dictionary

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Element

A

An element is one of the values in a list (or other data collection type); elements can also be called items.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Encapsulation

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Flow of Execution

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Function Definition

A

A function definition specifies the name of a new function and the sequence of statements that execute when the function is called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Global Scope

A

Global scope means variables can be accessed throughout the entire program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Indefinite Iteration
A loop that is not specified in advance on how many times to be run; it repeats as long as a condition is met. In Python, indefinite loops are typically created using the while loop.
26
Index
The index (also known as position) is an integer value that indicates an element in a data collection type like a list.
27
Infinite Loop
An infinite loop is a loop in which the terminating condition is never satisfied or for which there is no terminating condition.
28
Iterable
Iterable sounds complex but it is just a fancy name for a Python object that is capable of going through its members one at a time.
29
Iteration
Iteration is the repetition of a process. For programming, that is basically the repetitive execution of code to do something.
30
Iteration Variable
The variable that changes each time the loop executes and controls when the loop finishes.
31
Iterator
Iterator is a type of object that contains a countable number of values. More simply, the iterator is an object that can be used to traverse and move through all its values (elements) within an iterable object.
32
List
The list is the simplest data collection type in Python and it can store multiple values in a single variable.
33
Local Scope
Local scope means that the variables can only be accessed within the block, function, method, or class that they are initialized or used.
34
Mutable
Mutable means that we’re able to change items, add items, or delete items from a data collection type after it has been created.
35
None
The type None is a return type that simply means that there is no data that’s returned.
36
Recursion
With recursion, we have a function call itself with a base case to exit the recursive cycle.
37
Return Statement
The return statement is an important part of functions and methods as it allows the functions and methods to return Python objects back to the code that called them. The return statement is the actual line that starts with the word 'return'.
38
Return Value
These objects that are being returned from the return statement are called the function or method’s return value.
39
Sets
Sets are a data collection type that is used to store multiple elements in a single variable similar to the other data collection types. Set elements are unordered and unchangeable.
40
Tuple
A tuple is a data collection type that is ordered and unchangeable. This means that a tuple uses an indexing structure for its order and its elements can’t be changed after it has been defined.
41
break
This is a reserved keyword that creates a break statement for loops. The break statement can immediately terminate a loop’s execution. When this occurs, the program goes to the first statement/line of code after the loop.
42
continue
This is a reserved keyword that creates a continue statement for loops. The continue statement will end the current loop iteration, meaning that the execution jumps back to the top of the loop. The expression is then evaluated to determine if the loop will execute again or end there.
43
def
The reserved keyword def indicates that you are defining a function.
44
del
del is a reserved keyword and used as the del statement to delete an element. It does not return anything.
45
dict()
The dict() function creates a new dictionary with no elements.
46
divmod()
The divmod() function takes in two numbers as arguments and returns two numbers in a tuple.
47
end
The end parameter is a function of the print() function. Using the end parameter, we are able to change the default operation of the print() function, namely to prevent the print() function from creating a new line.
48
for
In Python, definite iteration loops are generally called for loops. Python’s for loop is a data collection-based iteration (loops through iterable objects such lists, sets, tuples, dictionaries, and even strings).
49
isinstance()
The isinstance() function takes in a variable and the data type as parameters and returns if that variable is of that datatype or not.
50
iter()
The iter() function is used to create an iterator by initializing the object that was passed to it.
51
key:value pair
A key:value pair is used with the dictionary data collection type. Think of a dictionary as a mapping between the index positions (which are called the keys) and a set of values (elements). Each key maps to a value. The association of a key and a value (element) is called a key:value pair.
52
len()
The len function (stands for length) returns the number of elements in a list (or other data collection type).
53
max()
The max function (stands for maximum) returns the largest value in a list (or other data collection type).
54
min()
The min function (stands for minimum) returns the smallest value in a list (or other data collection type).
55
next()
The next() function is used to move to the next value (element) in an iterable object.
56
raise
The raise statement allows the programmer to force a specified exception to occur when it is called.
57
range()
The range() function takes multiple parameters, the starting number (0 by default), and the ending number. This function will increment by 1 (by default) and then stop before a designated number. The function can take an optional third parameter to change the step value (increment or decrement by a specific value other than the default of 1).
58
return
The reserved keyword return is used to exit a function and return a value, either an optional return value we specify or None if no value is specified.
59
slice
The slice operator also works on lists which allows us to return or update specific elements within the list. The slice operator works on any data collection types that are ordered, so this operator will work with lists and tuples.
60
sum()
The sum function returns a number, sum of all values in a list (or other data collection type).
61
while
The while loop is one of the most commonly used loops. It keeps going as long as some condition is true.