typestar

Dicts and Sets in Julia

Pairs with =>, membership with in, dedup for free.

# Dicts map keys to values with =>; Sets deduplicate.
exposures = Dict("M42" => 120, "M31" => 300)
exposures["M45"] = 90

println(exposures["M31"])
println(get(exposures, "M13", 0))

for (target, secs) in sort(collect(exposures))
    println("$target: $secs s")
end

seen = Set(["Vega", "Altair", "Vega"])
push!(seen, "Deneb")
println("Summer triangle logged? ", length(seen) == 3)

How it works

  1. Dict("M42" => 120) builds; indexing assigns new keys.
  2. get(dict, key, default) reads without risking a KeyError.
  3. Set deduplicates on construction and on push!.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
377
Tokens
110
Three-star pace
65 tpm

At the three-star pace of 65 tokens a minute, this run takes about 102 seconds.

Type this snippet

Step 2 of 3 in Collections, step 11 of 27 in Language basics.

← Previous Next →