Sort tuples using lambda as key Dry Run in PYTHON

Sort tuples using lambda as key is an interactive PYTHON dry run visualizer from the Special programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Sort tuples using lambda as key Program Code

# List of tuples (name, age, score)
students = [("Alice", 22, 85), ("Bob", 19, 92), ("Charlie", 21, 78), ("Diana", 20, 95)]

# Sort by age (second element)
by_age = sorted(students, key=lambda x: x[1])

# Sort by score (third element) descending
by_score = sorted(students, key=lambda x: x[2], reverse=True)

print("Sorted by age:", by_age)
print("Sorted by score (highest first):", by_score)

View the complete Special programs page.

Program Console Sort tuples using lambda as key Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.