Sort by Largest Digit(s)
05AB1E, 5 bytes
ΣêR}R
Try it online! or as a Test suite
Explanation
Σ } # sort input by
ê # its sorted unique characters
R # reversed (to sort descending)
R # reverse the result (to sort descending)
Python 2, 60 55 54 bytes
-1 byte thanks to Jonas Ausevicius.
def f(l):l.sort(cmp,lambda n:sorted(set(`n`))[::-1],1)
Try it online!
Ungolfed
def f(l):
l.sort( # Sort the list in place
cmp = cmp, # ... compare with the builtin function cmp
key = k, # ... on the function k
reverse = 1 # ... in reverse
) # As the arguments are used in the right order, no names are necessary.
k = lambda n:sorted( # sort
set(`n`) # ... the set of digits
)[::-1] # reverse the result
# As '-' is smaller than the digits,
# it will be sorted to the back and ignored for sorting
Try it online!
Perl 6, 36 34 33 31 bytes
-1 byte thanks to Jo King
-2 bytes thanks to Phil H
*.sort:{sort 1,|set -<<m:g/\d/}
Try it online!
Explanation
{ } # Map each number, e.g. -373
m:g/\d/ # Extract digits: (3, 7, 3)
-<< # Negate each digit: (-3, -7, -3)
set # Convert to set to remove duplicates
| # Pass as list of pairs: (-3 => True, -7 => True)
1, # Prepend 1 for "none": (1, -3 => True, -7 => True)
sort # Sort (compares 1 and pair by string value): (-7 => True, -3 => True, 1)
*.sort: # Sort lexicographically