godotengine / godotengine/godot-docs

About dictionaries, can two items associate to the same value?

Open
#4,487 2 comments 0 reactions 0 assignees View on GitHub
area:class reference enhancement
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

Reading [this article](https://docs.godotengine.org/en/stable/classes/class_dictionary.html) it stated “Dictionaries are composed of pairs of keys (which must be unique) and values.”

So I was wondering when it meant “unique” is that each one item in the pair (A) must be associated with only ONE of the other item in the pair (B).

However, can two different items be associated to the same, while it cannot have one item associated to multiple items? (like being akin to [function in mathematics with ordered pairs](https://en.wikipedia.org/wiki/Function_(mathematics)#Definition))

Something like this:
```
var my_dir = {} # Creates an empty dictionary.
var points_dir = {"White": 50, "Yellow": 50, "Orange": 50}
```
But you cannot do this:
```
var my_dir = {} # Creates an empty dictionary.
var points_dir = {"White": 50, "White": 75, "Orange": 50}
```

If yes, someone should update that document to say this instead:

“Dictionary type. Associative container which contains values referenced by unique keys. Dictionaries are composed of pairs of things; a key (which must be unique) and a value (two keys can associate to the same value). Dictionaries will preserve the insertion order when adding elements, even though this may not be reflected when printing the dictionary. In other programming languages, this data structure is sometimes referred to as an hash map or associative array.”

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.