Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can you get enter two functions or values in Lambda function

Sorry if the question is confusing or stupid but basically in a sorted function I want Lambda to check the names and if they both have the same name check to see which house comes for example

def get_name(list):
    return list['Names'], list['House']

would check the name then the house they’re in can lambda do the same or just take one parameter

for student in sorted(students, key=lambda studen: studen['Names']):
    print(f"{student['Names']} is in {student['House']}")

PS: I’m trying to write a lambda expression that is the same as get_name

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Simply have your lambda return a tuple:

sorted(students, key=lambda student: (student['Names'], student['House']))

Or alternatively, using the get_name function that you defined:

sorted(students, key=get_name)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading