Junior — Middle
Kuidas eristada komplekti, millel on unikaalsed elemendid, sõnastikust, millel on võtmed ja väärtused?
sobes.tech AI
Vastus AI-lt
A set with unique elements (Set) is a collection that stores only unique values without key-value pairs. For example, in Swift, a Set contains only elements, and each element can appear only once.
A Dictionary is a collection of key-value pairs, where each key is unique and associated with a specific value.
Example in Swift:
let uniqueNumbers: Set = [1, 2, 3, 3, 4] // contains 1, 2, 3, 4
let dict: [String: Int] = ["one": 1, "two": 2]
Here, Set stores only unique numbers, and Dictionary stores "key-value" pairs.