Print int[string] sorted by Value
Paul Backus
snarwin at gmail.com
Wed Oct 28 15:25:26 UTC 2020
On Wednesday, 28 October 2020 at 15:15:40 UTC, Paul wrote:
> per the D sample wc2.d....
> size_t[string] dictionary; <-is printed by...
> .....
> foreach (word1; dictionary.keys.sort) writef ....etc
>
> I want to print the dictionary sorted by value not key. I can
> write an algorithm but is there a library method(s) I can use
> to iterate through the array sorted by decreasing values?
>
> Thanks for your time.
import std.array, std.algorithm;
auto sorted = dictionary.byPair.array.sort!((a, b) => a.value <
b.value)
More information about the Digitalmars-d-learn
mailing list