I need to sort a dictionary file before I format it. I used list.sort and it put it in ascii order (capital letters before lowercase). So I found this code online to do the sort. It works, but I don't fully understand how the lambda works with 2 variables and with cmp(). I am confused as to what cmp is comparing and which two variables lambda is using. Please explain how lambda works with cmp inside of the sort function.
f = open("swedish.txt", 'r')
f2 = open("swed.txt", 'w')
doc = f.read().split('\n')
doc.sort(lambda x, y: cmp(x.lower(), y.lower()))
for line in doc:
f2.write(line + '\n')
f.close()
f2.close()