pythonfor x in S: subgroup[typeof(x)].append(x) for t, xs in subgroup: result[t] = f(xs)
pythonfor x in S: result[typeof(x)].update(x)