Funnily enough I actually implemented this [0] two semesters ago while working as a Teacher's Assistant for the into CS class.
It worked fairly well. I basically took the levenshtein algorithm and mapped it directly to ASTs and used that to find the % of similar elements in the code. It worked a few times and I caught 1 or 2 groups of cheaters.
....sadly in that class you were allowed to "work together" you just had to include a note saying you did so I've got no "kill count" anymore and I'm not planning on TAing any time soon (at least not for python).
Also that code was hacked together in a weekend and that anti-cheet was done in 2-3 hr. It's not production ready by a longshot.
[0] - https://github.com/gravypod/GradeO/blob/master/libs/cheating...