Re: Key and value with ranges

2023-10-03 Thread christian.koestlin via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 20:22:30 UTC, Andrey Zherikov wrote: On Tuesday, 3 October 2023 at 19:57:06 UTC, christian.koestlin wrote: On Tuesday, 3 October 2023 at 01:55:43 UTC, Andrey Zherikov wrote: On Monday, 2 October 2023 at 18:46:14 UTC, christian.koestlin wrote: [...] Slightly

Re: Key and value with ranges

2023-10-03 Thread Andrey Zherikov via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 19:57:06 UTC, christian.koestlin wrote: On Tuesday, 3 October 2023 at 01:55:43 UTC, Andrey Zherikov wrote: On Monday, 2 October 2023 at 18:46:14 UTC, christian.koestlin wrote: [...] Slightly improved: ```d import std; [...] Thanks .. the thing with ref result

Re: Key and value with ranges

2023-10-03 Thread christian.koestlin via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 01:55:43 UTC, Andrey Zherikov wrote: On Monday, 2 October 2023 at 18:46:14 UTC, christian.koestlin wrote: [...] Slightly improved: ```d import std; [...] Thanks .. the thing with ref result is very clever! Should `ref result` be `return result`? Kind regards,

Re: Key and value with ranges

2023-10-02 Thread Joel via Digitalmars-d-learn
On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: ```d import std; auto data=“I went for a walk, and fell down a hole.”; ``` [snip] How can I improve this code? Like avoiding using foreach. This works for me: ```d import std; auto data="I went for a walk, and fell down a hole.";

Re: Key and value with ranges

2023-10-02 Thread Andrey Zherikov via Digitalmars-d-learn
On Monday, 2 October 2023 at 18:46:14 UTC, christian.koestlin wrote: On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: How can I improve this code? Like avoiding using foreach. You could fold into a hash that counts the occurrences like that: ```d import std.uni : toLower; import

Re: Key and value with ranges

2023-10-02 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 2 October 2023 at 20:20:44 UTC, Joel wrote: I want the output sorted by value. Look: https://forum.dlang.org/post/qjlmiohaoeolmoavw...@forum.dlang.org ```d struct SIRALA(T) { } ``` You can use SIRALA(T). Okay, his language is Turkish but our common language is D. His feature

Re: Key and value with ranges

2023-10-02 Thread Joel via Digitalmars-d-learn
On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: ```d import std; auto data=“I went for a walk, and fell down a hole.”; void main(string[] args) { int[string] dic; struct WordCnt { string word; ulong count; string toString() const { return

Re: Key and value with ranges

2023-10-02 Thread Joel via Digitalmars-d-learn
On Monday, 2 October 2023 at 06:19:29 UTC, Imperatorn wrote: On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: ```d import std; auto data=“I went for a walk, and fell down a hole.”; You can improve it further by inlining ```d import std; auto data = "I went for a walk, and fell down a

Re: Key and value with ranges

2023-10-02 Thread christian.koestlin via Digitalmars-d-learn
On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: How can I improve this code? Like avoiding using foreach. You could fold into a hash that counts the occurrences like that: ```d import std.uni : toLower; import std.array : split, array; import std.stdio : writeln; import std.algorithm :

Re: Key and value with ranges

2023-10-02 Thread Imperatorn via Digitalmars-d-learn
On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: ```d import std; auto data=“I went for a walk, and fell down a hole.”; You can improve it further by inlining ```d import std; auto data = "I went for a walk, and fell down a hole."; void main(string[] args) { int[string] dic;

Re: Key and value with ranges

2023-10-01 Thread Imperatorn via Digitalmars-d-learn
On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: ```d import std; auto data=“I went for a walk, and fell down a hole.”; void main(string[] args) { int[string] dic; struct WordCnt { string word; ulong count; string toString() const { return