len, sorted, zip, enumerate, map, filter โ these show up in nearly every Python interview. Drill every built-in so none catch you off guard when the clock is ticking.
Given the string "42", write the call that converts it to the integer 42.
Given the string "3.14", write the call that converts it to the float 3.14.
Given the integer 42, write the call that converts it to the string "42".
Given the integer 1, write the call that converts it to a boolean True.
Given t = (1, 2, 3), write the call that converts it to the list [1, 2, 3].
Given lst = [1, 2, 3], write the call that converts it to the tuple (1, 2, 3).
Given lst = [1, 2, 2, 3], write the call that converts it to the set {1, 2, 3}.
Given lst = [1, 2, 3], write the call that builds an immutable frozenset from it.
Given pairs = [("a", 1), ("b", 2)], write the call that builds the dict {"a": 1, "b": 2}.
Given the string "hello", write the call that converts it to a UTF-8 encoded bytes object.
Given lst = [65, 66, 67], write the call that builds a mutable bytearray from it.
Write the call that constructs a base object instance with no arguments.
Given lst = [10, 20, 30], write the call that creates a memoryview over a bytes object built from it. (Use bytes(...) as the argument.)
Write the call that builds a slice object representing [1:10:2].
Given lst = [1, 2, 3] and the function str, write the call that returns an iterator yielding "1", "2", "3".
Given lst = [1, 2, 3, 4], write the call that returns an iterator over only the even numbers (use a lambda).
Given nums = [1, 2, 3] and letters = ["a", "b", "c"], write the call that returns an iterator yielding (1, "a"), (2, "b"), (3, "c").
Given lst = ["a", "b", "c"], write the call that returns an iterator yielding (0, "a"), (1, "b"), (2, "c").
Given lst = [3, 1, 4, 1, 5], write the call that returns the new sorted list [1, 1, 3, 4, 5].
Given lst = [1, 2, 3], write the call that returns a reverse iterator over it.
Write the call that produces a range object yielding 0, 1, 2, 3, 4.
Given lst = [1, 2, 3], write the call that returns an iterator over it.
Given an iterator it, write the call that returns the next item from it (raising StopIteration if exhausted).
Given an async iterable aiter_obj, write the call (Python 3.10+) that returns an async iterator over it.
Given an async iterator ait, write the call (Python 3.10+) that awaits the next item from it.
Given the integer -5, write the call that returns its absolute value.
Given lst = [3, 1, 4, 1, 5], write the call that returns the smallest element.
Write the call that returns the smaller of 3 and 7, passing them as two separate arguments (not in a list).
Given lst = [3, 1, 4, 1, 5], write the call that returns the largest element.
Write the call that returns the larger of 3 and 7, passing them as two separate arguments (not in a list).
Given lst = [1, 2, 3, 4], write the call that returns the sum 10.
Given the float 3.14159, write the call that rounds it to 2 decimal places.
Write the call that computes 2 ** 10 using the built-in (returns 1024).
Write the call that returns both the quotient and remainder of 17 / 5 as the tuple (3, 2).
Given flags = [True, True, False], write the call that returns False (because not every item is truthy).
Given flags = [False, False, True], write the call that returns True (because at least one item is truthy).
Given lst = [1, 2, 3], write the call that returns its length 3.
Write the call that prints "Hello, World!" to stdout.
Write the call that prompts the user with "Name: " and reads a line from stdin.
Write the call that opens the file "data.txt" for reading in text mode (default).
Given the float 3.14159, write the call that formats it with 2 decimal places using the format-spec mini-language (returns "3.14").
Given the string "hello", write the call that returns its quoted printable representation (e.g. "'hello'").
Given the string "hรฉllo", write the call that returns an ASCII-only repr with non-ASCII chars escaped.
Given the value 42, write the call that returns its type (<class 'int'>).
Given the value 42, write the call that returns True if it is an instance of int.
Given the class bool, write the call that returns True because bool is a subclass of int.
Given the value x, write the call that returns its unique identity as an integer.
Given the string "hello", write the call that returns its hash value.
Given the value 42, write the call that returns a list of attribute names available on it.
Given an object obj, write the call that returns its __dict__ (the namespace mapping).
Given an object obj, write the call that returns its attribute named "name".
Given an object obj, write the call that sets its attribute "name" to "Ada".
Given an object obj, write the call that returns True if it has an attribute named "name".
Given an object obj, write the call that deletes its attribute named "name".
Given the function print, write the call that returns True because it is callable.
Given the integer 65, write the call that returns the corresponding character "A".
Given the character "A", write the call that returns its Unicode code point 65.
Given the integer 255, write the call that returns its hexadecimal string "0xff".
Given the integer 8, write the call that returns its octal string "0o10".
Given the integer 5, write the call that returns its binary string "0b101".
Given the string expression "2 + 2", write the call that evaluates it and returns 4.
Given the source string "x = 1", write the call that executes it as a statement (returns None).
Given the source string "2 + 2", write the call that compiles it as an expression named ".
Write the call that returns the current global symbol table as a dict.
Write the call that returns the current local symbol table as a dict.
Inside a method, write the call that returns a proxy object for delegating method calls to the parent class (no arguments).
Write the call that creates a property descriptor from a getter function get_x.
Write the call that wraps a function func as a class method (usually used as a decorator).
Write the call that wraps a function func as a static method (usually used as a decorator).
Write the call that imports the module named "math" dynamically (rarely used directly โ prefer importlib.import_module).
Write the call (Python 3.7+) that drops into the configured debugger at the current line of code.
Given the built-in str, write the call that opens its interactive help in the REPL.
// finished? submit your full attempt