Re: Sort Associative Array by Key

2019-08-28 Thread a11e99z via Digitalmars-d-learn
On Tuesday, 27 August 2019 at 20:35:16 UTC, bachmeier wrote: On Tuesday, 27 August 2019 at 20:14:21 UTC, Machine Code wrote: It isn't really hard: It really is hard. foo.byPair.array.sort!((a, b) => a.key < b.key).map!(a => a.value); is a lot to digest for someone learning the language.

Re: Sort Associative Array by Key

2019-08-28 Thread berni via Digitalmars-d-learn
On Tuesday, 27 August 2019 at 16:25:00 UTC, Samir wrote: As I've mentioned on the list before, I really struggle to understand how some of the std.algorithm functions such as `map` work when combined with things like `array`, `sort` and especially `zip` but really appreciate the support I find

Re: Sort Associative Array by Key

2019-08-27 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 27 August 2019 at 20:14:21 UTC, Machine Code wrote: It isn't really hard: It really is hard. foo.byPair.array.sort!((a, b) => a.key < b.key).map!(a => a.value); is a lot to digest for someone learning the language. There's a big difference between not being hard for someone

Re: Sort Associative Array by Key

2019-08-27 Thread Machine Code via Digitalmars-d-learn
On Tuesday, 27 August 2019 at 16:25:00 UTC, Samir wrote: On Sunday, 25 August 2019 at 17:01:23 UTC, a11e99z wrote: auto foo = ["VXE":8, "BZP":5, "JLC":2]; foo.byPair.array.sort!"a[0] On Sunday, 25 August 2019 at 19:03:10 UTC, JN wrote: I think normal lambdas are better than these string ones:

Re: Sort Associative Array by Key

2019-08-27 Thread Samir via Digitalmars-d-learn
On Sunday, 25 August 2019 at 17:01:23 UTC, a11e99z wrote: auto foo = ["VXE":8, "BZP":5, "JLC":2]; foo.byPair.array.sort!"a[0] On Sunday, 25 August 2019 at 19:03:10 UTC, JN wrote: I think normal lambdas are better than these string ones: foo.byPair.array.sort!((a, b) => a[0] < b[0]).map!(a =>

Re: Sort Associative Array by Key

2019-08-25 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 25 August 2019 at 19:03:10 UTC, JN wrote: I think normal lambdas are better than these string ones: foo.byPair.array.sort!((a, b) => a[0] < b[0]).map!(a => a[1]).writeln; You can also use names instead of numeric indices: foo.byPair.array.sort!((a, b) => a.key < b.key).map!(a =>

Re: Sort Associative Array by Key

2019-08-25 Thread JN via Digitalmars-d-learn
On Sunday, 25 August 2019 at 17:01:23 UTC, a11e99z wrote: On Sunday, 25 August 2019 at 16:54:33 UTC, Samir wrote: Is there a way to output the values of an associative array based on the lexicographic order of the keys? For example, if foo = ["VXE":8, "BZP":5, "JLC":2], I'd like to output

Re: Sort Associative Array by Key

2019-08-25 Thread a11e99z via Digitalmars-d-learn
On Sunday, 25 August 2019 at 16:54:33 UTC, Samir wrote: Is there a way to output the values of an associative array based on the lexicographic order of the keys? For example, if foo = ["VXE":8, "BZP":5, "JLC":2], I'd like to output something like: 5 2 8 auto foo = ["VXE":8, "BZP":5,

Sort Associative Array by Key

2019-08-25 Thread Samir via Digitalmars-d-learn
Is there a way to output the values of an associative array based on the lexicographic order of the keys? For example, if foo = ["VXE":8, "BZP":5, "JLC":2], I'd like to output something like: 5 2 8 Thanks! Samir

sort associative array by key

2012-11-23 Thread dsmith
What is the best way to have a function sort an associative array by key? The following yields a conversion error. double[string] aa_sort(double[string] aa) { return aa.keys.sort; }

Re: sort associative array by key

2012-11-23 Thread Andrej Mitrovic
On 11/23/12, dsmith d...@nomail.com wrote: What is the best way to have a function sort an associative array by key? The following yields a conversion error. double[string] aa_sort(double[string] aa) { return aa.keys.sort; } Hashes are unordered, you can't sort them by key because

Re: sort associative array by key

2012-11-23 Thread Timon Gehr
On 11/23/2012 07:09 PM, dsmith wrote: What is the best way to have a function sort an associative array by key? The following yields a conversion error. double[string] aa_sort(double[string] aa) { return aa.keys.sort; } A hash table is unsorted by definition. What is it that you want

Re: sort associative array by key

2012-11-23 Thread dsmith
On Friday, 23 November 2012 at 18:24:07 UTC, Timon Gehr wrote: On 11/23/2012 07:09 PM, dsmith wrote: What is the best way to have a function sort an associative array by key? The following yields a conversion error. double[string] aa_sort(double[string] aa) { return aa.keys.sort

Re: sort associative array by key

2012-11-23 Thread Timon Gehr
On 11/23/2012 07:48 PM, dsmith wrote: On Friday, 23 November 2012 at 18:24:07 UTC, Timon Gehr wrote: On 11/23/2012 07:09 PM, dsmith wrote: What is the best way to have a function sort an associative array by key? The following yields a conversion error. double[string] aa_sort(double[string