Which fix removes the inefficiency?
out = ''
for row in rows:
out += row + ','
- Build once with
','.join(rows)instead - Build once with
','.append(rows)instead - Change
out = ''toout = []only - Use
out = out + rowinside the loop
Strings are immutable, so += rebuilds the whole string each pass; join builds it once.
Play Problem Solving ▸