1/80
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What are collections?
Prepackaged data structures of related data items
What are the four built-in data types in Python used to store collections of data?
List, tuple, set, dictionary
How is a list created?
By placing elements inside square brackets ([]), separated by commas.
What is the difference between lists and tuples in Python?
Lists are modifiable (mutable), while tuples are not (immutable).
What do list typically store?
Homogeneous data
Can list store heteogenous data?
Yes
What can list do as necassary?
Dynamically resize
What function can be used to determine the length of a list?
Len
What does the sum function do?
adds all the numbers in a range
Are python's string mutable or immutable?
Mutable
What method can be used to concatenate two lists in Python?
Using the + operator or += operator.
Tuple items are:
ordered, unchangeable
Do tuple items allow duplicate values?
Yes
How is a tuple created?
By placing a sequence of comma-separated items inside round brackets ()
How can you create an empty tuple in Python?
By using empty parentheses ()
How do we pack a tuple?
By separating its values with commas
What is required to create a one-element tuple?
A Comma
e.g: ('red,)
What does the tuple() function do?
convert other iterable objects (like lists, strings, sets, or dictionaries) into an immutable tuple, or to create an empty tuple.
What comparison operator can be used with tuples, even though they are immutable?
+=
What does += do when used with tuples?
Creates new objects
Can tuples contain mutable objects?
Yes
How can we unpack a sequence's elements?
By assigning the sequence to a comma-separated list of variables
What is the purpose of the enumerate() function?
To access an element's index and value in an iterable.
What does enumerate() receive?
An iterable which it uses to create an iterator that, for each element, returns a tuple containing the element's index and value
Why are sequences sliced?
To create new sequences of the same type containing subsets of the original elements
Slice operations that do not modify a sequence work identically for?
lists, tuples, and strings
How do we modify lists via slices?
By using the syntax: example_list[start:stop:step] = new_iterable
What does the del function do?
Deletes target from the list
How do we delete an element from a list?
using the syntax: del variable_name[gini #]
How do we delete a slice from a list?
using the syntax: del variable_name [ : ]
How do we delete a variable from a list?
using the syntax: del variable_name
What does the .sort() method do in Python?
It modifies a list in place to sort its elements.
What does the sorted() function do?
It returns a new list containing the sorted elements of its argument sequence.
What is the significance of the term 'immutable' in relation to tuples?
It means that once a tuple is created, its elements cannot be changed.
How can you access elements of a list?
By using their index, e.g., G[0], G[1], etc.
How do we insert an object at a specific list index?
.insert(gini position, variable to be inserted)
How can you add an element to the end of a list?
.append()
How can you add all the elements of a sequence to the end of a list?
.extend()
What function removes the first occurrence of an element in a list?
.remove
What is the method to count occurrences of an item in a list?
.count()
How do we empty a list?
Using [ ]
What is list comprehension in Python?
A concise way to create lists by iterating over an iterable and applying an expression.
What does the for clause in a list comprehension do?
It iterates over a sequence and evaluates an expression for each item.
For each item, what does list comprehension evaluate?
The expression to the left of the 'for' clause and places the expression's value in the new list
How do you replace an item in a list?
By assigning a new value to the specific index of the list.
What does the term 'homogeneous data' refer to in lists?
Data that consists of elements of the same type.
What does it mean for lists to be dynamic in size?
Lists can grow or shrink in size as items are added or removed.
What is the difference between mutable and immutable objects?
Mutable objects can be changed after creation, while immutable objects cannot.
What is mapping in the context of list comprehension?
A functional-style programming operation that produces a result with the same number of elements as the original data.
What is the purpose of the zip() function?
To iterate over multiple iterables and produce tuples of corresponding elements.
What does zip() receive?
Any number of iterables and returns and iterator that produces tuples containing the elements are the same index in each
What is the NumPy library used for?
It is the preferred Python array implementation, critical for big-data processing and AI applications.
What is an ndarray in NumPy?
A high-performance, n-dimensional array type that is up to 100 times faster than Python lists.
How can you create a NumPy array from existing data?
By using the array() function with an iterable as an argument.
What is the argument for the array() function?
an array or other iterable
What does the array() function return?
A new array containing the argument's elements
What do array Attributes do?
Enable you to discover information about its structure and contents
What function allows you to discover element type in arrays?
.dtype
What function allows you to discover element dimension in arrays?
.ndim
What function allows you to discover element shape in arrays?
.shape
What function allows you to discover element size in arrays?
.size/.itemsize
What does the .itemsize function do?
Shows the number of bytes required to store each element
What is the purpose of the zeros(), ones(), and full() functions in NumPy?
To fill arrays with specific values.
How are the zeros(), ones(), and full() fuctions converted in array?
np.zero, np.ones, np.full
What do array operators do?
Perform arithmetic operations and augmented assignments between arrays of the same shape
What does the itemsize attribute of a NumPy array indicate?
The number of bytes required to store each element in the array.
How do you select an element in a two-dimensional NumPy array?
By specifying the row and column indices in square brackets.
What is a deep copy in Python?
A copy of an object that is completely independent of the original, created using the .copy() method.
What are the characteristics of a set in Python?
Sets are unordered, unchangeable, and do not allow duplicate values.
What is a dictionary in Python?
A collection that is ordered, changeable, and does not allow duplicates.
How can you access elements in a dictionary?
Using methods like item(), keys(), and values().
What methods can be used to add or remove data in a dictionary?
You can use methods like del and pop() to delete data, and simply assign values to add data.
What is the output of the code print(type({'Vladimir', 34, 55000}))?
C: set
What is the command to store a copy of a list in Python?
my_list_original = my_list.copy()
What is the significance of the NumPy library in scientific computing?
It provides a core library for efficient numerical operations and is foundational for many data science libraries.
What does the term 'slicing' refer to in the context of arrays?
Selecting a subset of elements from an array based on specified indices.
What is the output of the command my_list = [12, 23, 43, 21]; my_list_original = my_list?
my_list_original refers to the same list as my_list, not a copy.
What is the purpose of the comparison operations in NumPy?
To perform element-wise comparisons, producing arrays of Boolean values.
What is the role of universal functions in NumPy?
To perform mathematical, trigonometric, and comparison operations on arrays.
What is the difference between a set and a dictionary in Python?
A set is unordered and unindexed with no duplicates, while a dictionary is ordered, changeable, and does not allow duplicates.
What does the function .pop() do?
remove and return a specific element