Of course, the normal caveats apply (dicts aren't ordered so there's no filtering involved, if "Adam" and "Apple" are both in your input, only the second will find its way into the output, etc). To take care of the latter problem, you might want to consider a collections.defaultdict: