learnbyexample@programming.dev to Python@programming.devEnglish · 7 months agoA Guide to Python Lambda Functionsadamj.euexternal-linkmessage-square8fedilinkarrow-up133arrow-down10
arrow-up133arrow-down1external-linkA Guide to Python Lambda Functionsadamj.eulearnbyexample@programming.dev to Python@programming.devEnglish · 7 months agomessage-square8fedilink
minus-squaretunetardislinkfedilinkEnglisharrow-up2·7 months agoActually, now that I think of it, there’s no reason you need to join the 2 names into a single str. You could just leave it as a tuple of last, first and Python will know what to do in comparing them. >>> sorted(student_ids, key = lambda i: ((rec := student_recs[i])['last'], rec['first'])) [632453, 1261456, 532153] So the lambda would be returning ('Potter', 'Harry') rather than 'Potter, Harry'. But whatever. The := part is still the same.
Actually, now that I think of it, there’s no reason you need to join the 2 names into a single
str
. You could just leave it as atuple
of last, first and Python will know what to do in comparing them.So the lambda would be returning
('Potter', 'Harry')
rather than'Potter, Harry'
. But whatever. The:=
part is still the same.