How to drop pairs in dict

Solution 1:

The unwanted keys are inside x here:

{k :[x for x in dic1[k] if (x.keys()) == {'word', 'group'}] for k, in dic1}

You need one more dict comprehension inside your comprehension:

out = {k: [{k2:v2 for k2,v2 in x.items() if k2 not in ('time', 'session')} for x in v1] for k, v1 in dic1.items()}

Output:

{'a': [{'word': '3', 'group': 'a'},
  {'word': '1', 'group': 'b'},
  {'word': '0', 'group': 'c'}]}

Solution 2:

Here's the code which only keeps needed fields:

    dic2 = {k :[{'word':x['word'], 'group' : x['group']} for x in dic1[k]] for k, in dic1}