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

# List -- length or cardinality of a list, hash table, dictionary, set, or string

Description

If x is a list, #x is the number of elements in x.

i1 : L = {1, 2, 3, 2, 1};
i2 : #L

o2 = 5

If x is a set, #x is the cardinality of x.

i3 : S = new Set from L

o3 = set {1, 2, 3}

o3 : Set
i4 : #S

o4 = 3

If x is a hash table, #x is the number of key-value pairs stored in x.

i5 : T = new HashTable from {a => 1, b => 2}

o5 = HashTable{a => 1}
               b => 2

o5 : HashTable
i6 : #T

o6 = 2

If x is a string, #x is the number of characters in x.

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

o8 = 40

See also

Ways to use this method:

  • # BasicList
  • # Dictionary
  • # HashTable
  • # List -- length or cardinality of a list, hash table, dictionary, set, or string
  • # Net
  • # Sequence
  • # Set
  • # String

The source of this document is in Macaulay2Doc/ov_hashtables.m2:758:0.