Append Set to Set
Consider the sets a={1} and b={2}. As output I want {1,{2}}. I tried
sage: a={1};b={2}
sage: a.add(b)
and
sage: a.union({b})
but both attempts result in an error:
TypeError: unhashable type: 'set'
Consider the sets a={1} and b={2}. As output I want {1,{2}}. I tried
sage: a={1};b={2}
sage: a.add(b)
and
sage: a.union({b})
but both attempts result in an error:
TypeError: unhashable type: 'set'
To circumvent this problem the frozenset (which can't be modified after creation) was invented:
sage: a.add(frozenset(b))
sage: a
{1, frozenset({2})}
Another alternative is to use Sage's Set:
sage: a=Set([1])
sage: b=Set([2])
sage: a.union(Set([b]))
{1, {2}}
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2022-04-12 17:29:02 +0100
Seen: 469 times
Last updated: Apr 12 '22
How do I get the classical N1 object rather than N*? (NN)
plot unions, intersections, etc.
How do I create subsets of sets?
how to print the weight multiplicites in a column
Similar command to Mathematica's Reduce[]?
How do I define (and work with) a set of matrices?
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.