www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Create a List or Dictionary.

reply Sunny <yove pm.me> writes:
Hello, I'm having a problem, how can I create a List or 
Dictionary in D?



var musicList = new List <(string URL, string Artist, string 
Title, string Cover, string Duration)> ();

In Google did not find anything, tell me please how to get out of 
this situation?
Jun 18 2018
next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
On 18/06/2018 11:44 PM, Sunny wrote:
 Hello, I'm having a problem, how can I create a List or Dictionary in D?
 

 
 var musicList = new List <(string URL, string Artist, string Title, 
 string Cover, string Duration)> ();
 
 In Google did not find anything, tell me please how to get out of this 
 situation?
https://dlang.org/spec/arrays.html#dynamic-arrays https://dlang.org/spec/hash-map.html
Jun 18 2018
prev sibling parent reply Cym13 <cpicard openmailbox.org> writes:
On Monday, 18 June 2018 at 11:44:43 UTC, Sunny wrote:
 Hello, I'm having a problem, how can I create a List or 
 Dictionary in D?



 var musicList = new List <(string URL, string Artist, string 
 Title, string Cover, string Duration)> ();

 In Google did not find anything, tell me please how to get out 
 of this situation?
If I read you well it seems the simplest equivalent code would be: struct MusicItem { string URL; string Artist; string Title; string Cover; string Duration; } MusicItem[] musicList; You could technically use tuples to get to the same point but I don't really see a point, structs fit that purpose very well. Then you can: musicList ~= MusicItem(url, artist, title, cover, duration); musicList = [musicItem1, musicItem2]; or for dictionnaries: MusicItem[string] musicDictionnary = [ "shortID1": MusicItem(foo, bar, baz, bak, biz, sub), "shortID2": MusicItem(foo, bar, baz, bak, biz, sub), ]; etc.
Jun 18 2018
parent reply Sunny <yove pm.me> writes:
On Monday, 18 June 2018 at 13:23:37 UTC, Cym13 wrote:

Yes, this is what need, thank you very much for your help. :-)

 On Monday, 18 June 2018 at 11:44:43 UTC, Sunny wrote:
 [...]
If I read you well it seems the simplest equivalent code would be: struct MusicItem { string URL; string Artist; string Title; string Cover; string Duration; } MusicItem[] musicList; You could technically use tuples to get to the same point but I don't really see a point, structs fit that purpose very well. Then you can: musicList ~= MusicItem(url, artist, title, cover, duration); musicList = [musicItem1, musicItem2]; or for dictionnaries: MusicItem[string] musicDictionnary = [ "shortID1": MusicItem(foo, bar, baz, bak, biz, sub), "shortID2": MusicItem(foo, bar, baz, bak, biz, sub), ]; etc.
Jun 18 2018
parent reply Cym13 <cpicard openmailbox.org> writes:
On Tuesday, 19 June 2018 at 05:52:00 UTC, Sunny wrote:
 On Monday, 18 June 2018 at 13:23:37 UTC, Cym13 wrote:

 Yes, this is what need, thank you very much for your help. :-)

 [...]
I recommend that you take the D tour if you can, it explains all those fundamental features quite well I think. https://tour.dlang.org/
Jun 19 2018
parent reply Sunny <yove pm.me> writes:
On Tuesday, 19 June 2018 at 09:07:46 UTC, Cym13 wrote:
 On Tuesday, 19 June 2018 at 05:52:00 UTC, Sunny wrote:
 On Monday, 18 June 2018 at 13:23:37 UTC, Cym13 wrote:

 Yes, this is what need, thank you very much for your help. :-)

 [...]
I recommend that you take the D tour if you can, it explains all those fundamental features quite well I think. https://tour.dlang.org/
I read about D here - https://www.tutorialspoint.com/d_programming/index.htm figured it all out, but with a convenient implementation of the sheets there was a problem.
Jun 19 2018
parent ag0aep6g <anonymous example.com> writes:
On 06/19/2018 11:50 AM, Sunny wrote:
 I read about D here - 
 https://www.tutorialspoint.com/d_programming/index.htm
I'd advise against using that tutorial. Last time I looked at it, it seemed to be of low quality [1]. And the better parts seemed to be stolen from Ali Çehreli's "Programming in D", which is available for free, too: http://ddili.org/ders/d.en/ [1] https://forum.dlang.org/post/onstqa$255e$1 digitalmars.com
Jun 19 2018