Jun-17-2020, 09:22 AM
I was checking up on sorting 2D lists, and found this (works fine):
but when i replaced takeFirst with "chicken", it also worked !
Question: by what mechanism does takeFirst() know what "elem" is?
thx,
Paul
#sort on first element def takeFirst(elem): return elem[0] # list lst = [(2, 2), (3, 4), (4, 1), (1, 3)] # sort lst.sort(key=takeFirst) # print list print('Sorted list:', lst)At first i thought that takeFirst, takeSecond, were some kind of "reserved" words,
but when i replaced takeFirst with "chicken", it also worked !
Question: by what mechanism does takeFirst() know what "elem" is?
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.