brock@montreat:~/csci431/webpage/notes$ python3 Python 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from itertools import groupby >>> things = [("animal", "bear"), ("animal", "duck"), ("plant", "cactus"), ("vehicle", "speed boat"), ("vehicle", "school bus")] >>> magic = groupby(things, lambda x: x[0]) >>> for x in magic: ... print(x[0]) ... for y in x[1]: ... print(" {0}".format(y[1])) ... animal bear duck plant cactus vehicle speed boat school bus >>>