this post was submitted on 29 Apr 2024
34 points (100.0% liked)

Python

6375 readers
5 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[โ€“] tunetardis@lemmy.ca 2 points 6 months ago

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 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.