ret = ""
for s in strings:
ret += s
is that it re-allocates O(n) times, even if ret is referenced only once. def reduce(acc, f):
for v in self:
acc = f(acc, v)
return acc
The current acc goes out of scope each time you call f. There's no shared reference (assuming f doesn't sneak store it elsewhere, which for string combining, f should just be `return a+b`?).