2

I have a list of lists (that might have any number of lists as entries) and want to find the union of this list (as a set) in Sage. I would think there is a short existing command already but I was not able to find it.

Here an example:

W=[[2, 1], [2], [3, 1], [1]]
T=W.union()
display(W)
display(T)

The desired output is T=[1,2,3] but it seems the command "union" does not work.

Mare
  • 123
  • 3

1 Answers1

2

You can use set().union()

W=[[2, 1], [2], [3, 1], [1]]
T=set().union(*W)
print(W)
print(T)
Lakshan Costa
  • 623
  • 7
  • 26