"dictionaries" function: "keys"/"values"

Those functions mentioned above also work with lists; or I'm wrong?

1 Like

I would not advise mixing them.

Tables break the uniqueness rules of dictionaries:

Notice how the dictionary blocks only return the last key and value for a duplicate column 1 tag.

1 Like

Yes, that's what I saw playing with it. But it's logic because a dictionary, to my experiences, is built on the basis of distinct keys by which a value can be identified. Therefore, I think, in the dictionaries blocks doesn't exist an "additem" but a "set..." instead for the case that a value is to be changed that has been stored under a certain key - to avoid duplicating. However, when I use lists the type of keys/values is conserved. Assumed a list of pairs has distinct "keys" it works. Furthermore the "look up in pairs" is similar to that, it takes the first entry out of entries with the same key. --- It would be great if it worked with lists; for this use I had written own "keys"/"values" for lists in the past that I wouldn't need anymore in this special case of all distinct keys.

For a long time, associative lists were the only way to represent key-value data in App Inventor using built-in datatypes. When we implemented dictionaries in the language (which are more efficient for the same task), we decided that it should be possible to interchange between the two representations since older components/extensions might expect associative lists. Likewise, people might be more comfortable using associative lists but a component may expect a dictionary instead. Rather than having blocks for explicit casts between the two types, we made it so that the language will convert between the two representations automatically based on the data type needed. If your list data isn't in associative list format, this conversion will not work--i.e., the list must contain pairs and nothing else.


Thank you for your detailed statement. That's what I found while exploring the blocks. If I understand right way, I can use "keys/values" for, you call it "associative" lists (a new terminus for me), without any problems as long as they are made of pairs. And so far I didn't have any problems using them with "keys/values". The possibilities given are unlimited as pairs can also consist of pairs... That dictionaries are different from lists I noticed by call the "do" (right mouse button). It appears an expression between curly brackets as opposed to "normal" lists (round brackets). I'm not quite familiar with all details in JS, but there I saw objects constructed the same way. Well, you have helped me to look a bit behind the scene.

1 Like