Loved the answer using the redu () function. Here's another way to sort a string using the accumulate () method.
from itertools import accumulate s = 'mississippi' print(tuple(accumulate(sorted(s)))[-1])
sorted (s) → ['i', 'i', 'i', 'i', 'm', 'p', 'p', 's', 's', 's', 's']
tuple (accumulate (sorted) (s)) → ('i', 'ii', 'iii', 'iiii', 'iiiim', 'iiiimp', 'iiiimpp', 'iiiimpps',' iiiimppss', 'iiiimppsss ',' iiiimppssss')
We select the last index (-1) of the tuple
Mono Sep 04 '18 at 10:21 2018-09-04 10:21
source share