pyassistant

Sort words by number of unique characters (stable)

Given a list of lowercase words, return a new list where the words are ordered by the number of distinct characters each word contains, in descending order. If two words have the same number of distinct characters, preserve their original relative order (stable sort).

Example:

Input:
(['apple', 'banana', 'car', 'door'],)
Output:
['banana', 'apple', 'door', 'car']

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.