Code Room
Code reviewMedium
Question
Review this Python function that runs many independent lookups in a loop.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
def enrich(pool, ids): results = {} for id_ in ids: conn = pool.getconn() cur = conn.cursor() cur.execute("SELECT name FROM users WHERE id = %s", (id_,)) row = cur.fetchone() if row is None: continue results[id_] = row[0] cur.close() pool.putconn(conn) return resultsRun or narrate your approach, then ask the coach.