Answers for "sorted and lambda in python yt"

4

python sorted lambda

a = ["tim", "bob", "anna", "steve", "john"]

# sorts the list by the first letter of each name
b = sorted(a, key=lambda x : x[0])
# x = each of the values in the list a

# sorts the list by length FIRST, then alphabetical order SECOND
c = sorted(a, key=lambda x : (len(x), x))
Posted by: Guest on November-10-2021
0

sorted lambda

sorted(student_tuples, key=lambda student: student[2])
Posted by: Guest on April-21-2021

Python Answers by Framework

Browse Popular Code Answers by Language