Chapter 7 Key Terms Flashcards
Sequence
Is an ordered collection of elements that can be of any data type. Ex: strings, tuples, lists.
List
Is a mutable, ordered collection of elements using square brackets ‘[]’.
Mutable
Elements can be modified after it is created. Change, add, or remove.
Dynamic Data Structure
Structure that can change size by changing, adding, or removing elements.
Repetition Operator *
Is used to repeat a sequence a specified number of times.
Index
A numerical value that represents the position of an element within a sequence.
Starting Index
The index of the first element in a sequence.
Index of Last Element
The last element in a sequence can be found using the formula len(sequence) - 1, where len(sequence) is the length of the sequence.
IndexError Exception
An exception occurs when you try to access an index that is outside the valid range of indices for a sequence.
len
Is used to determine the number of elements in a sequence.
Concatenating Lists
Combining two or more lists into a single list.
Slice
Extracting a portion of a sequence by specifying a range of indices.
in
Is used to check if a particular element exists within a sequence.
append
Is used to add an element to the end of a list.
index
Is used to find the index of the first occurrence of a specified element in a list.
insert
Is used to add an element at a specific index within a list.
sort
Is used to arrange the elements of a list in ascending order.
remove
Is used to remove the first occurrence of a specified element from a list.
reverse
Is used to reverse the order of elements in a list.
del
Is used to remove an element or slice from a list by specifying the index or range of indices.
min
Is used to find the smallest element in a list.
max
Is used to find the largest element in a list.
Copying a List
Creating a new list with the same elements as the original list.
Adding Values in a List
Involves using methods like append or insert.
Averaging Values in a List
Summing up the elements in the list and dividing the sum by the number of elements.
Passing a List as an Argument
A list can be passed as an argument to a function so that the list within it can be operated on or altered.
Returning a List from a Function
A function can return a list as a result, which allows lists to be created and returned with specific data.
List Comprehension
Allows you to create a new list by applying an expression to each item in an iterable.
Result Expression
Defines what will be included in the new list.
Iteration Expression
Specifies how to iterate over an iterable within a list comprehension.
if Clause
Is used to filter elements from the source iterable based on a condition.
Two-Dimensional List
Each element of the outer list is itself a list.
Row
One of the inner lists or sub lists.
Column
A specific element at the same index in each of the inner lists.
Tuple
Is an ordered, immutable collection of elements in Python, defined using parentheses ‘()’.