I need help with counting each individual value that appears in a Dictionary List

Hey everyone,

Newbie here, I am having trouble on working with Dictionary lists. Now suppose I have a Dictionary List variable called FruitPerson where the key variable is a ‘String’ and so is the Value. The elements in this variable are {{Kiwi, John Smith}, {Banana, Paul Williams}, {Peach, John Smith}, {Plum, Amy Louise}, {Orange, Oscar Davis}, {Lime, Paul Williams}, {Lemon, John Smith}}

Now I want to count the number of times that each name appears in this list and assign this as a value onto another Dictionary List called PersonCount where this time, the person’s name is the key values. I am looking to have this variable show like this:

{{John Smith, 3}, {Paul Williams, 2}, {Amy Louise, 1}, {Oscar Davis, 1}

Is there anyway that I can count the individual values from the initial, FruitPerson variable to help with creating the new list that which shows how many times they appeared in this list?

2 Likes

Have a look here:

Assign Activity:
myReportDict | Dictionary(Of String, int32) =

myOrigDict.GroupBy(Function (kvp) kvp.Value).ToDictionary(Function (x) x.Key, Function (x) x.Count)

Hi @sukh.johal

PersonCount = FruitPerson
.GroupBy(pair => pair.Value)
.ToDictionary(group => group.Key, group => group.Count());

Thanks