Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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))
 
PREVIOUS NEXT
Tagged: #python #sorted #lambda
ADD COMMENT
Topic
Name
9+8 =