Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » lists and sequences » List # ZZ
next | previous | forward | backward | up | index | toc

List # ZZ -- get value from list, hash table, database, dictionary, or string

Description

If x is a list, x#i returns the ith element of x. The entries of the list are numbered starting with 0. If i is negative, then the entries are numbered ending with -1. If i is out of range, an error is signaled.

i1 : L = {a, b, c, b, a};
i2 : L#2

o2 = c

o2 : Symbol
i3 : L#-2

o3 = b

o3 : Symbol

If x is a hash table or database, x#i provides the value associated with the key i.

i4 : T = new HashTable from {a => 103, b => 89.4, c => 92};
i5 : T#a

o5 = 103
i6 : T#b

o6 = 89.40000000000001

o6 : RR (of precision 53)

If x is a string, x#i provides the ith character of x, if there is one. Negative indices are counted backward from the end, as with lists. If i is out of range, an error is thrown.

i7 : s = "a perfectly adequate example of a string";
i8 : s#2

o8 = p
i9 : s#-2

o9 = n

Assignment to x#i can change x if x is mutable.

i10 : V = new MutableHashTable from T;
i11 : V#a = 5;
i12 : V#d = 22.3;
i13 : peek V

o13 = MutableHashTable{a => 5   }
                       b => 89.4
                       c => 92
                       d => 22.3

See also

Ways to use this method:

  • BasicList # ZZ
  • Database # String
  • Dictionary # String
  • HashTable # Thing
  • List # ZZ -- get value from list, hash table, database, dictionary, or string
  • Net # ZZ
  • Sequence # ZZ
  • String # ZZ

The source of this document is in /build/reproducible-path/macaulay2-1.25.05+ds/M2/Macaulay2/packages/Macaulay2Doc/ov_hashtables.m2:817:0.