Retrieving specific entries from dictionary

Hi,

Let’s assume that I build a dictionary following this general format:

VarName | Entry
—————————
“A” | “Joe”
“C” | “Susi”
“B” | “Pete”

etc. - note that VarName is not alphabetical.

The workflow first initialized the dictionary using assign Dict = New dictionary(Of String,String), and then adds the entries individually using assign (first entry “A”, then entry “C” etc.).

Now, 2 questions:

  • In what order will the entries of the dictionary be? In the order they were added, or in alphabetical order? Will adding new entries change the order of existing entries?
  • How can I retrieve the value (“Entry”) of specific elements? I.e. how can I retrieve, say, the value of the 3rd element by position, as well as by VarName (“B”)?

Let me elaborate on the second point. My goal is to retrieve values in (more or less) random order, i.e. not sequentially. E.g. I’ve tried using Dict.elementat(1).key and Dict.elementat(1).value (as well as Dict.elementat(0).key and Dict.elementat(0).value), but I can’t figure out the logic of what is returned.

Any help would be appreciated,

Philipp

PS I am aware of Dictionaries - #7 by ClaytonM

@Philipp_Maier Can you tell us What is returned? Also how exactly you need the output to appear as?

I hope you want to retrieve the values based on the index or the order you added the value in the dictionary right? @Philipp_Maier

Actually arrays of lists are meant to do that, but you can also do that in dictionary. but you need to use as dictionary.keys(index)

Ah! Thanks to @hareeshMR and @supermanPunch I think that I now better understand where the problem lies.

The attached workflow replicates the problem statement from the original post, with entries A-C. I also added an entry D, which is really long. Retrieving that long entry results in nothing being returned.

Any suggestions how to handle long entries? Would a different structure (e.g. datatable instead of dictionary) solve this? Note that my original problem relies on building out the dictionary based on an Excel file, so it’s not about manually adding entries, but rather any solution needs to be able to handle dynamically building a structure of unknown length and filling it with values, based on looking up references in a spreadsheet.

Thanks for your help,

Philipp

Main.xaml (6.7 KB)
project.json (686 Bytes)

Hi.

A dictionary is put simply just a list of key value pairs, so they will always be in the order they were added. New entries will be added onto the bottom of the list.

To call a value based on the key (VarName in your case) you would use the following

Dict.Item(VarName).tostring

the .tostring is redundant but I make a habit of adding it in to be sure the value is retrieved as a string.

I’m not sure of the use case for being able to call the value by position.