I have a very large collection of (p, q) tuples that I would like to convert into a dictionary of lists where the first item in each tuple is a key that indexes a list that
Here is the iterator style of doing it
>>> mylist=[(1, 2), (1, 3), (2, 3)] >>> from itertools import groupby >>> from operator import itemgetter >>> mylist=[(1, 2), (1, 3), (2, 3)] >>> groupby(mylist,itemgetter(0)) >>> list(_) [(1, ), (2, )]