Sets
Array elements are ordered, but can contain duplicates, that is, the same value can occur at different indices. In a dictionary, keys have to be unique, but the values do not, and the keys are not ordered. If you want a collection where order does not matter, but where the elements have to be unique, then use a Set. Creating a set is easy as this:
// code in Chapter 5\sets.jl: s = Set({11, 14, 13, 7, 14, 11})
The Set()
function creates an empty set. The preceding line returns Set{Int64}({7,14,13,11})
, where the duplicates have been eliminated. From v0.4 onwards, the {}
notation with sets is deprecated; you should use s = Set(Any[11, 14, 13, 7, 14, 11])
. In the accompanying code file, the latest version is used.
The operations from the set theory ...
Get Julia: High Performance Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.