When I tallied GTU (Gujarat Technological University) Physics papers for juniors, the hardest part was not the code. It was deciding what "repeated" means, so the numbers do not lie to you.
The setup
22 official GTU Physics question papers, Summer 2022 to Summer 2026, across three subject codes (3110011, 3110018 and the new BE01000021), downloaded from GTU's own repository. Text came out with pdftotext , then every sub-question, including the OR options, got a topic tag.
Rule 1: count a topic once per paper
If Ruby laser shows up in Q.3(c) and again in Q.5(a) OR, that is still one paper. Otherwise a single paper that loves lasers inflates the count.
from collections import defaultdict
def papers_per_topic ( tagged ): # tagged: list of (paper_id, topic) for every sub-question seen = defaultdict ( set ) for paper_id , topic in tagged : seen [ topic ]. add ( paper_id ) return { t : len ( p ) for t , p in seen . items ()}
Enter fullscreen mode
Exit fullscreen mode
The set does all the work.…