Macaulay2 » Documentation
Packages » Macaulay2Doc :: # BasicList
next | previous | forward | backward | up | index | toc

# BasicList -- length or cardinality

Synopsis

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: