Editor

Sort by Last Character

Beginner · Write the code · from Python Lambda Functions: When to Use (and When Not To)

From the lesson: Python Lambda Functions: When to Use (and When Not To)

Imagine you need to leave someone a quick note: "Back in 5 minutes." You wouldn't write a formal letter with a greeting, three paragraphs, and a signature. You'd scribble it on a sticky note and be done.

Read the lesson

Given a list of words, use sorted() with a lambda to sort them by their last character. Print the resulting sorted list.

Use this list: words = ['hello', 'world', 'python', 'code']

Expected output: ['world', 'code', 'python', 'hello']

words = ['hello', 'world', 'python', 'code']
# Sort by last character and print

More Lambda exercises

All Python exercises · 50 practice problems · Functions quiz