Junior — Middle
Can you explain the main differences between array, dictionary, and set in the context of programming?
sobes.tech AI
Answer from AI
The main differences between array, dictionary, and set:
-
Array — an ordered collection of elements, accessed by index. Allows duplicates and preserves order.
-
Dictionary (or Map) — a collection of key-value pairs, where each key is unique and maps to a value. Accessed by key.
-
Set — an unordered collection of unique elements, without duplicates. Used for fast lookup and existence checks.
Example in Python:
arr = [1, 2, 2, 3] # Array with duplicates
dict = {'a': 1, 'b': 2} # Dictionary with keys 'a' and 'b'
set_ = {1, 2, 3} # Set of unique elements
```n