That is interesting observation. I'm curious if using collections.deque for the accumulator could speed it even further for long strings.
As per the docs:
It looks like the benefit is when pop or insert on/from the left side of the deque.
As per the docs:
Quote:Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.
Though list objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation.
It looks like the benefit is when pop or insert on/from the left side of the deque.