sot/timelines — comment on commit 5ade2a9ccae7265d86d9b47d15eb87f6db205bb9
File:  line 0
By taldcroft:

I *think* this version still suffers from unnecessary deletes / re-inserts. The patches have made the logic even more intricate and I have trouble determining if it will work. Fixing the unnecessary delete will make it worse.

The fundamental problem starts with the lack of distinction between falling through the mismatch loop without ever finding a mismatch and finding a mismatch on the last value. I think you should start over with the original cmd_states logic which doesn't have this problem. You were learning Python when writing timelines but now you should be comfortable with `zip`, `count()`, and the `for - else` idiom.