How to measure similarity between two python code blocks?
<p>Many would want to measure code similarity to catch plagiarisms, however my intention is to cluster a set of python code blocks (say answers to the same programming question) into different categories and distinguish different approaches taken by students. </p>

<p>If you have any idea how this could be achieved, I would appreciate it if you share it here.</p>

<p>One approach would be to count then number of functions, objects, keywords <em>possibly grouped into categories such as branching, creating, manipulating, etc.,</em> and number variables of each type.  Without relying on the methods and variables being called the same name(s).</p>

<p>For a given problem the similar approaches will tend to come out with similar scores for these, e.g.: A students who used decision tree would have a high number of branch statements while one who used a decision table would have much lower.</p>

<p>This approach would be much quicker to implement than parsing the code structure and comparing the results.</p>

python compilation comparison abstract-syntax-tree