Macaulay2 » Documentation
Packages » Macaulay2Doc > The Macaulay2 language > hash tables > pairs
next | previous | forward | backward | up | index | toc

pairs -- list the pairs in a hash table, dictionary, or basic list

Synopsis

Description

If x is a hash table or dictionary, the pairs consist of each key along with its associated value.

i1 : x = new HashTable from {a => 1, b => 2, c => 3}

o1 = HashTable{a => 1}
               b => 2
               c => 3

o1 : HashTable
i2 : pairs x

o2 = {(c, 3), (a, 1), (b, 2)}

o2 : List

A dictionary is a special hash table whose keys are strings, and whose values are the corresponding symbols.

i3 : d = new Dictionary

o3 = d

o3 : GlobalDictionary
i4 : getGlobalSymbol (d, "foo")

o4 = foo

o4 : Symbol
i5 : getGlobalSymbol (d, "bar")

o5 = bar

o5 : Symbol
i6 : pairs d

o6 = {(bar, bar), (foo, foo)}

o6 : List
i7 : first oo

o7 = (bar, bar)

o7 : Sequence
i8 : class \ oo

o8 = (String, Symbol)

o8 : Sequence

If x is a basic list, the pairs consist of each index along with the element at that index in the list.

i9 : L = {3, 5, 7};
i10 : pairs L

o10 = ((0, 3), (1, 5), (2, 7))

o10 : Sequence
i11 : pairs {apple, banana, carrot}

o11 = ((0, apple), (1, banana), (2, carrot))

o11 : Sequence

Caveat

As the first example illustrates, pairs are not necessarily listed in any particular order.

See also

Ways to use pairs :

For the programmer

The object pairs is a compiled function.