Why is There No "Get Key From Value in Dictionary?"

Frankly, I'm quite surprised there's no method to get the key from a value in a Dictionary. I know there isn't one in Java, but since there's a get keys block, here's what I think should solve it:
image

Not a very great suggestion as such, but it would definitely be beneficial to beginners in App Inventor.

5 Likes

7 Likes

To avoid an error:

5 Likes

True! good to understanding AI2 technicality.

"Unlocking a lock with a key" but here you have greatly introduced, “unkeying the key with a lock”.

3 Likes

I think it should be get keys from value in Dictionary, as duplicated values are accepted. A for-loop can solve this.

2 Likes

Normally what one would do in this situation is use a double bookkeeping system where you have two dictionaries to model the bidirectional nature of the relationship. The benefit of how dictionaries are implemented is that looking up a key in the dictionary is a constant-time operation whereas scanning all of the key-value pairs is linear in the size of the dictionary. The additional overhead of implementing this internally to App Inventor (and paid by every app that uses the dictionary) likely wouldn't be worth the small number of use cases in which the behavior would be valuable.

7 Likes