Why this matters
Reduces code size and avoids missed branches when adding cases.
Replace repeated similar if/elif blocks with data-driven loops or dispatch tables.
Reduces code size and avoids missed branches when adding cases.
Side-by-side examples engineers can pattern-match during review.
if k == 'a': out['a'] = f(v)
elif k == 'b': out['b'] = f(v)
elif k == 'c': out['c'] = f(v)for k in ['a','b','c']:
out[k] = f(source[k])if x==1: ... elif x==2: ... elif x==3: ...handlers = {1: h1, 2: h2, 3: h3}; handlers[x]()From the same buckets as this rule.