Efficiently keeping track of changes in text
Question: I have to send some text over the network to another computer in python. I'll
probably do this using sockets. I'm doing this so people on two different
computers can edit a document at the same time. I was wondering whether there
was an efficient way I could do this. I figure sending the updated text
everytime a user presses a key doesn't make sense at all. Could I instead only
send the changes that are made every time the user changes something in the
text. How do I go about doing this?


Answer: As you want to allow editing text to 2 (or more) clients, I would use a patch
library such as diff_match_patch (google diff match patch).

Here is a sample code you can use :

    
    
    import diff_match_patch as dmp
    
    d = dmp()
    patch = d.patch_make(current_text, new_text)
    updated_text, status = d.patch_apply(patch, current_text)
    

So you can handle insertions, deletions and can even add undo operations...

