Code Lab BetaBUILD. RUN. DISCOVER.
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON STRUCTURES / CHAPTER 06 / Learn / LESSON 10
lambda — a small anonymous function in one expression:
pairs = [("b", 2), ("a", 3)]
print(sorted(pairs, key=lambda p: p[0]))key= chooses what to sort by. Without key Python compares the items themselves (here tuples lexicographically).
Learn: key= with lambda.
PROFILE IDLE
›