What's Columns?
> However using Cardinality() on ComSet does not seem to work:
>
> ComSet.Cardinality()
>
> Basically I am looking for the mathematica command "Length".
FYI, most Python and Sage commands start with a lower case. In this
case, however, what you're looking for is len(ComSet). If you have an
object x, type x-dot-tab to see what methods it supports.
> Furthermore how would I be able to map that command on to the elements
> of ComSet?
Use "list comprehensions" (it's a Python thing).
sage: L = [[1, 2, 3], [4, 5]]
sage: [len(a) for a in L]
[3, 2]
--
To post to this group, send email to sage-s...@googlegroups.com
To unsubscribe from this group, send email to sage-support...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-support
URL: http://www.sagemath.org
sage: ComSet, type(ComSet), len(ComSet)
([[[0, 1], [0, 2], [1, 2]], [[0, 1, 2]], [[0, 1], [0, 2], [1, 2]]],
<type 'list'>, 3)
sage: ComSet[0], type(ComSet[0]), len(ComSet[0])
([[0, 1], [0, 2], [1, 2]], <type 'list'>, 3)
sage: ComSet[0][0], type(ComSet[0][0]), len(ComSet[0][0])
([0, 1], <type 'list'>, 2)
sage: ComSet[0][0][0], type(ComSet[0][0][0])
(0, <type 'int'>)
cardinality is a method not of Python lists, but of the Combinations
object. For example:
sage: C
Combinations of [0, 1, 2] of length 2
sage: C.cardinality()
3
sage: list(C)
[[0, 1], [0, 2], [1, 2]]
sage: C.list()
[[0, 1], [0, 2], [1, 2]]
sage: len(C.list())
3
The reason tab-completion doesn't reveal len is because len is a
function, not a method on the object, and the dot-tab procedure
returns the object's contents. (Admittedly, if you type
ComSet.__[tab], you can see the special methods, including
ComSet.__len__ which is used behind the scenes, but you would never
write ComSet.__len__() in real code.)
Does that help?
Doug
Thanks,
This really has clarified everything :)
Much appreciated,
Vince