def first_item(aList):
    return aList[0]
sorted(list(kwargs.items()), key=first_item)
from operator import itemgetter
sorted(list(kwargs.items()), key=itemgetter(0))
Understand lambda usage in given python code