Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Associations

$ wo '<|"Green" -> 2, "Red" -> 1|>'
<|Green -> 2, Red -> 1|>
$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>'
<|Green -> 2, Red -> 1|>

Access values in associations

$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; myHash[["Green"]]'
2
$ wo 'myHash = <|1 -> "Red", 2 -> "Green"|>; myHash[[1]]'
Red
$ wo 'assoc = <|"a" -> True, "b" -> False|>; assoc[["b"]]'
False

Update Values

$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; myHash[["Green"]] = 5; myHash'
<|Green -> 5, Red -> 1|>

Add Values

$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; myHash[["Puce"]] = 3.5; myHash'
<|Green -> 2, Red -> 1, Puce -> 3.5|>

KeyExistsQ

$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; KeyExistsQ[myHash, "Red"]'
True

KeyDropFrom

$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; KeyDropFrom[myHash, "Green"]'
<|Red -> 1|>

Keys

$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; Keys[myHash]'
{Green, Red}

Values

$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; Values[myHash]'
{2, 1}

Nested access

$ wo 'assoc = <|"outer" -> <|"inner" -> 8|>|>; assoc["outer", "inner"]'
8

Map

$ wo 'assoc = <|"a" -> 2, "b" -> 3|>; Map[#^2&, assoc]'
<|a -> 4, b -> 9|>

AssociationThread

$ wo 'AssociationThread[{a, b, c}, {1, 2, 3}]'
<|a -> 1, b -> 2, c -> 3|>

Merge

$ wo 'Merge[{<|a -> 1|>, <|a -> 2, b -> 3|>}, Total]'
<|a -> 3, b -> 3|>

KeyMap

$ wo 'KeyMap[f, <|a -> 1, b -> 2|>]'
<|f[a] -> 1, f[b] -> 2|>

KeySelect

$ wo 'KeySelect[<|1 -> a, 2 -> b, 3 -> c|>, EvenQ]'
<|2 -> b|>

KeyTake

$ wo 'KeyTake[<|a -> 1, b -> 2, c -> 3|>, {a, c}]'
<|a -> 1, c -> 3|>

KeyDrop

$ wo 'KeyDrop[<|a -> 1, b -> 2, c -> 3|>, {a}]'
<|b -> 2, c -> 3|>