Generate a password
05AB1E, 19 17 16 bytes
Saved 1 byte thanks to Kevin Cruijssen
áΣl}.γl}éεgyθJ}J
Try it online! or as a Test Suite
Explanation
á # keep only letters in input
Σl} # sort by lower-case
.γl} # group by lower-case
é # sort by length (stable)
ε } # map each to
g # its length
J # joined with
yθ # the last letter
J # join to string
C# (Visual C# Interactive Compiler), 105 bytes
x=>x.Where(char.IsLetter).GroupBy(a=>a%32).OrderBy(a=>(a.Count(),a.Key)).Select(a=>a.Count()+""+a.Last())
Try it online!
Thanks to dana for bringing it down to 105 bytes from 138 bytes.
Japt v2.0a0 -P
, 14 bytes
f\l üv ñÊ®ÌiZÊ
Try it
f\l üv ñÊ®ÌiZÊ :Implicit input of string
> e.g., "Kitkat Tango"
f :Split to an array of characters
\l : Matching RegEx /[a-z]/gi
> ["K","i","t","k","a","t","T","a","n","g","o"]
ü :Sort & group (Preserves original order within each group)
v : By lowercase
> [["a","a"],["g"],["i"],["K","k"],["n"],["o"],["t","t","T"]]
ñ :Sort
Ê : By length
> [["g"],["i"],["n"],["o"],["a","a"],["K","k"],["t","t","T"]]
® :Map each Z
Ì : Last element of Z
> ["g","i","n","o","a","k","T"]
i : Prepend
ZÊ : Length of Z
> ["1g","1i","1n","1o","2a","2k","3T"]
:Implicitly join & output
> "1g1i1n1o2a2k3T"