Im having an empty dictionary:
Dictionary<List<string>, int> occurrences = new Dictionary<List<string>, int>();
And this is my jagged list:
List<List<string>> jaggedList = new List<List<string>>();
And x is the number of first elements that i was about to count in the jagged list. In this example:
x=2;
But i want it to change it myself whenever i get a "thicker" sublists than x+1
Jagged list:
{ cc kk ww }
{ cc kk aa }
{ cc oo ll }
{ cc jj oo }
{ ww oo kk }
{ ww oo gg }
{ ww gg kk }
{ kk ll oo }
{ ll kk nn }
{ mm nn oo }
{ mm nn jj }
I am completely hopeless with LINQ so i can not do it myself. I want my occurrences dictionary to get grouped x indexed elements in TKeyand its occurrences count in the TValue, so the result would look like:
Keys: Values:
{ cc kk } 2 //because those appear together in this order in 2 sublist(s)
{ cc oo } 1 //because those appear together in this order in 1 sublist(s)
{ cc jj } 1 //et cetera
{ ww oo } 2
{ ww gg } 1
{ kk ll } 1 //<-note that those do not appear in this order twice
{ ll kk } 1
{ mm nn } 2
As a hint i also have a linq command that does the same, except not with lists of string but with regular strings:
The strings i was talking about:
List<string> list = new List<string>();
{ gg }
{ gg }
{ jj }
{ ww }
{ ww }
{ jj }
{ mm }
{ ww }
{ ll }
{ kk }
{ ll }
Linq command:
var dic = list.GroupBy(b => b).ToDictionary(group => group.Key, group => group.Count());
The dictionary:
Dictionary<string, int> otherOccurrences = dic;
Result of it:
Keys: Values:
{ gg } 2 //because it appears in this list 2 time(s)
{ jj } 2 //same with this one
{ ww } 3 //et cetera
{ mm } 1
{ ll } 2
{ kk } 1
I would really appreciate the help with editing the specified linq command to get the one that would analogically do to the same to my occurrences. Feel free to correct me if im wrong somewhere. Im sorry if i did not make myself clear, feel free also to ask if you did not understand so i can explain it more specificly.
, int> occurrences = new Dictionary
, int>(); I didnt want x elements concatenated into one but literally x elements as a list. Could you help me again by fixing that?