Quizzes Flashcards
What is a dictionary in Python?
An unordered collection of key-value pairs
What is the primary requirement for keys in a Python dictionary?
They must be unique and immutable.
How can you create an empty dictionary in Python?
{}
What does the built-in function ‘len; return for a dictionary?
Number of key-value pairs.
How can you obtain a list of a dictionary’s keys in sorted order?
sorted(dict.keys())
What does the ‘==’ operator check for when used with dictionaries?
identical contents of key-value pairs.
What do dictionary comprehensions provide a convenient notation for?
Quickly generating dictionaries.
What is a set in Python?
An unordered collection of key-value pairs.
What is a significant characteristic of sets during iteration?
They are unordered
How can you create an empty set in Python?
set()
What is the recommended way to import the NumPy library?
import numpy as np
what does the NumPy array function do?
Copies its argument’s contents into the array
What attribute of an array provides information about its number of dimensions?
ndim
What does the ‘linspace’ function in NumPy do?
Produces evenly spaced floating-point ranges
What is broadcasting in NumPy
Performing element-wise calculations with a scalar and an array
What does element-wise arithmetic mean in the context of NumPy arrays?
Performing calculations on each element of an array.
How can you select an element in a two-dimensional array in NumPy?
Providing a tuple containing row and column indices
What is the difference between ‘reshape’ and ‘resize’ in NumPy?
‘resize’ modifies the original array; ‘reshape’ returns a view
How can you transpose an array in NumPy?
Using the ‘transpose’ method.
What does ‘vstack’ do in NumPy?
Combines two arrays by adding rows.