Reverse the order of a dictionary

Hello

My question is, how can I invert the order of a dictionary in a list of dictionaries?

Example:

This is an example dictionary within a dictionary list.

Normal:

New List(Of Dictionary(Of String, List(Of Object)) From {

New Dictionary(Of String, List(Of Object)) From {
{“value1”, New List(Of Object) From {“a”, “b”, “c”},
{“value2”, New List(Of Object) From {“d”, “e”, “f”},
{“value3”, New List(Of Object) From {“g”, “h”, “i”},
}

}

Expected result:

New List(Of Dictionary(Of String, List(Of Object)) From {

New Dictionary(Of String, List(Of Object)) From {
{“value3”, New List(Of Object) From {“g”, “h”, “i”},
{“value2”, New List(Of Object) From {“d”, “e”, “f”},
{“value1”, New List(Of Object) From {“a”, “b”, “c”},
}

}

It should be said that the keys in the dictionary are dynamic, they can be few or many, as they are dynamically extracted from another data source.

The dictionaries within the list are accessed through the index.

I hope you can help me

Hi

Hope this expression would help you resolve this

Use a assign activity like this

yourdictvar = yourDictVar.OrderByDescending(Function (x) x.key).ToDictionary(Function (x) x.Key,Function (x) x.Value)

Cheers @borismh

1 Like

Hi @borismh ,

Could you try with the Following Expression :

listDictVar.Select(Function(x)x.OrderByDescending(Function (y) y.key).ToDictionary(Function (a) a.Key,Function (b) b.Value)).ToList

Where listDictVar is of type List(Of Dictionary(Of String,List(Of Object)))

2 Likes

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