On Tuesday, 10 July 2018 at 14:58:42 UTC, vino.B wrote:

Hi Alex,

I am getting the output as tuples of multiple arrays, but the requirement is to get the all the tuple in a single array like the below so that we can perform sorting and printing the output is easy.

Something along the way

    unittest
    {
        import std.typecons : Tuple, tuple;
        alias pair = Tuple!(string, int);

        pair[] values;
        values ~= tuple("du", 7);
        values ~= tuple("Vino", 3);
        values ~= tuple(",", 4);
        values ~= tuple("hur", 5);
        values ~= tuple("Hej", 2);
        values ~= tuple("?", 8);
        values ~= tuple("mår", 6);

        import std.algorithm : sort, each;
        import std.stdio : write;
        values.sort!((p1, p2) => p1[1] < p2[1])
              .each!(p => write(p[0] ~ " "));
    }

?

Reply via email to