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 ss + t, s * n or n * ss[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 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, str, bytes, and bytearray
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
How can you use a list to simulate a stack
stack = [] stack.append(3) # push stack.pop() # pop len(stack) # num of element stack[-1] # peek if not stack # check empty
How can you simulate a queue
# Initialize a queue from collections import deque queue = deque() queue = deque([1,2,3]) queue.append(4) # Enqueue queue.pop() # deque queue[0] # peek len(queue) # get size
What built-in function returns the absolute value of a number
abs(x)
>>> abs(-10) 10 >>> abs(-3.145) 3.145
What built-in function converts a number to a binary string
bin(x)
>>> bin(10) '0b1010' >>> format(10,'b') '1010'
What built-in Python function returns the character corresponding to a given Unicode code point (integer)?
chr(i)
>>> chr(97)
'a'
>>> chr(ord('a'))
'a'What built-in function takes two (non-complex) numbers as arguments and returns a pair of numbers consisting of their quotient and remainder when using integer division
divmod(a, b)
>>> divmod(30,4) (7, 2)