Python Flashcards
What are the logical operators in Python
and
, or
, and not
What are the bitwise operators in Python
&
, |
, and ^
What are the priorities of the sequence operations in Python
x in s
, x not in s
s + t
, s * n
or n * s
s[i]
, s[i:j]
, s[i:j:k]
len(s)
min(s)
max(s)
s.index(x[, i[, j]])
s.count(x)
What sequence operation is used to test if an item exists in a sequence
x in seq
True
if x
exists in seq
, False
otherwisex not in seq
False
if x
exists in seq
, True
otherwise
What sequence operation is used to concatenate two sequences
seq1 + seq2
What sequence operation is used to repeat a sequence
seq * n
or n*seq
What sequence operation is used to return an element or slice of a sequence
seq[i]
return the ith element seq[i:j]
slice from i to j, not including jseq[i:j:k]
slice from i to j, not including j, with step k
What sequence operation is used to get the length of a sequence
len(seq)
the length of seq
What sequence operation is used to get the minimum value of a sequence
min(seq)
the smallest item of seq
What sequence operation is used to get the maximum value of a sequence
max(seq)
the largest item of seq
What sequence operation is returns the index of an object in a sequence
seq.index(x[,i[, j]])
index of the first occurrence of x (at or after index i and before index j)
What sequence operation is counts the number of occurrences of an object in a sequence
seq.count(x)
total number of occurrences of x
in seq
What are the basic sequence types in Python
list
, tuple
, range
What are Falsey values in Python
Constants defined to be false: None
and False
Numeric types that are zero: 0
, 0.0
, 0j
, Decimal(0)
, Fraction(0, 1)
Empty sequences and collections: ''
, ()
, []
, {}
, set()
, range(0)
What are Truthy values in Python
Constants defined to be true: True
Numeric types that are not zero
Non-empty sequences or collections
What data types are valid keys for a hash map/dictionary
Objects: Integer, Float, String, Boolean
Immutable sequences: String, Tuple, Range, Frozenset
For small inputs, an array can be faster than a hash map. Why?
There is overhead associated with a hash map such as the hash function
When designing a hash map what are some good design choices
- Use a prime number inf your hash function which helps spread the keys more evenly
- Design a hash function that spreads hashes evenly to avoid collisions
- Implement a method to handle collisions: chaining or open addressing