How to sort a dictionary by its Value

I have a dictionary<string, int> where Key: ‘Some Word’ and Value : ‘No of occurance’. I want to sort the dictionary order by No of occurance of the word from Maximum to the least.

give a try on
Use an assign activity:
left side: yourDictVar
Right side:

yourDictVar.OrderByDescending(Function (x) x.Value).ToDictionary(Function (x) x.Key,Function (x) x.Value)

it will overwrite the dictionary with the filtered dictionary

3 Likes

Hey @Iyash

I agree with @ppr but you could use invoke activity as well.

someVariable = in_dicObject.AsEnumerable().OrderByDescending(x => x.Value);
out_myDictionary = someVariable.ToDictionary(x => x.Key, x => x.Value)

And make sure to change Language to C#(because it’s an C# code)

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.