Ask Your Question
2

Set of lists behaves badly

asked 2025-11-25 14:14:31 +0100

I am running SageMath 10.6 (downloaded from binary) in a terminal under MacOS. The following happens:

sage: x = [[0],[0]]
sage: Set(x)
Set of elements of [[0], [0]]
sage: Set(x).cardinality()
2

There may be a workaround, but this shouldn't happen, should it?

edit retag flag offensive close merge delete

Comments

Max Alekseyev gravatar imageMax Alekseyev ( 2025-11-27 05:53:23 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2025-11-26 18:18:56 +0100

I think that in general, if you create a Set with elements that are not hashable, it will not behave perfectly. If you used x = [(0,), (0,)] instead, or equivalently

sage: x = [[0], [0]]
sage: y = [tuple(L) for L in x]
sage: Set(y)

then this will be better behaved.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2025-11-25 14:14:31 +0100

Seen: 55 times

Last updated: Nov 26