python
8 minPython Collections: Lists, Tuples, Sets, and Map/Reduce Trade-offs
Choose Python collection types by invariants and access patterns, then use map, comprehensions, and reductions without obscuring intent.
Loading page...
python
8 minChoose Python collection types by invariants and access patterns, then use map, comprehensions, and reductions without obscuring intent.
Q&A
Q&AAssociativity and an identity element make regrouping partial results meaningful.
A parallel reduction may group values differently, so its combine operation should be associative for equivalent results and have a suitable identity value. Floating-point addition can vary slightly with grouping. Avoid reducers with hidden side effects because execution order may not be stable.
Q&A
Q&AUse the form that makes transformation, laziness, and accumulator state easiest to understand.
map is lazy and can be concise with an existing named function; a comprehension often reads better when transformation and filtering are simple. reduce is appropriate for a well-defined associative fold, but sum, any, all, or an explicit loop often communicates intent better. Avoid hidden side effects because they make ordering and debugging difficult.
Q&A
Q&AThey reduce the runtime image to just the files required to execute the service.
Multi-stage a build lets you compile in one environment and then copy only the final artifact into a slim runtime image. This reduces image size, shortens deployment time, lessens the attack surface, and makes it easier to reason about what the service actually needs to run. It is a packaging discipline, not just a size optimization.
Q&A
Q&AUse repeated thread dumps and lock profiling to locate hot locks, then reduce serialization safely.
Capture repeated thread dumps and identify many threads blocked on the same owner or monitor. Use a profiler or JFR lock events to quantify contention and critical-section time. Reduce lock scope, shard independent state, batch updates, or use concurrent primitives only when they preserve the invariant; verify throughput and correctness under representative load.
Q&A
Q&AThe producer may reject writes when fewer than two replicas remain in the in-sync set.
With three brokers and min.insync.replicas=2, acks=all requires the current in-sync replica set to meet the minimum. If the ISR falls to one, writes are rejected rather than acknowledged with reduced replication. acks=1 favors availability but risks losing leader-only writes if that leader fails before replication.
devops
8 minReason about OIDC trust, token audience, job identity, and short-lived cloud credentials.
databases
8 minUse concurrent index builds without assuming they are lock-free or all-or-nothing.