How do I perform secondary sorting in python? July 22, 2023 by Tarik Sort it by a (firstkey, secondkey) tuple: sorted(list5, key=lambda vertex: (degree(vertex), vertex))