Re: Print int[string] sorted by Value

2020-10-28 Thread Ali Çehreli via Digitalmars-d-learn
On 10/28/20 9:30 AM, Paul wrote: > On Wednesday, 28 October 2020 at 15:40:23 UTC, aberba wrote: >> Have you tries .values() function? dictionary.values.sort() > > Thanks aberba. Yes, that was my first attempt! > > If my terminology is correct that gives me a "range" of sorted VALUES. No, both

Re: Print int[string] sorted by Value

2020-10-28 Thread Paul via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 15:27:04 UTC, H. S. Teoh wrote: foreach (key; aa.keys.sort!((a,b) => aa[a] < aa[b])) { writeln(key); This solution worked perfectly without modifying any of my other code. I don't fully understand it but can study up

Re: Print int[string] sorted by Value

2020-10-28 Thread Paul via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 15:40:23 UTC, aberba wrote: Have you tries .values() function? dictionary.values.sort() Thanks aberba. Yes, that was my first attempt! If my terminology is correct that gives me a "range" of sorted VALUES. I think I can't "iterate"(foreach) through an array

Re: Print int[string] sorted by Value

2020-10-28 Thread Paul via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 15:25:26 UTC, Paul Backus wrote: auto sorted = dictionary.byPair.array.sort!((a, b) => a.value < b.value) It seems this method produces a ?sorted array of tuples? [..Tuple!(string, "key", uint, "value")("Program", 74), Tuple!(string, "key", uint,

Re: Print int[string] sorted by Value

2020-10-28 Thread aberba via Digitalmars-d-learn
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

Re: Print int[string] sorted by Value

2020-10-28 Thread Paul via Digitalmars-d-learn
Thanks Teoh

Re: Print int[string] sorted by Value

2020-10-28 Thread Paul via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 15:25:26 UTC, Paul Backus wrote: 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

Re: Print int[string] sorted by Value

2020-10-28 Thread Paul Backus via Digitalmars-d-learn
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

Re: Print int[string] sorted by Value

2020-10-28 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 28, 2020 at 03:15:40PM +, Paul via Digitalmars-d-learn 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