output = [('studentA','ISDF'), ('studentB','CSE'),('studentC','BIO'),('studentA','ISDF'), ('studentB','CSE'),('studentC','BIO'),('studentA','ISDF'), ('studentB','CSE'),('studentC','BIO'),('studentA','ISDF'), ('studentB','CSE'),('studentC','BIO'),('studentA','ISDF'), ('studentB','CSE'),('studentC','BIO'),('studentA','ISDF'), ('studentB','CSE'),('studentC','BIO')]
so here there are total of 6 set of ('studentA','ISDF'), ('studentB','CSE'),('studentC','BIO') in this above list
so Im expecting an output like this ~
expected_output = [('studentA','ISDF',6), ('studentB','CSE',6),('studentC','BIO',6)]
The format should be [('student', 'department', total count)]
>Solution :
Try this:
sorted([tuple(list(item)+[output.count(item)]) for item in set(output)])