# Using union() and list comprehesions

**URL:** <https://discourse.julialang.org/t/using-union-and-list-comprehesions/46727>\
**Category:** New to Julia\
**Created:** [September 16, 2020, 7:56pm UTC](https://discourse.julialang.org/t/using-union-and-list-comprehesions/46727 "2020-09-16T19:56:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![asavasci](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asavasci](https://discourse.julialang.org/u/asavasci)\
**Post date:** [September 16, 2020, 7:56pm UTC](https://discourse.julialang.org/t/using-union-and-list-comprehesions/46727/1 "2020-09-16T19:56:42Z")

</div>

I have two-element array whose elements are Sets, x = [Set([:a,:b,:c]), Set([:c]) ], I would like to make union of the array elements as one resulting set, Set([:a, :b, :c]). I am having issue with union and iterate using list comprehensions over the array elements, Is there a better way to handle it?

```julia
x = [Set([:a,:b,:c]), Set([:c]) ]
union( x )
---
2-element Array{Set{Symbol},1}:
 Set([:a, :b, :c])
 Set([:c])

```

explicit specification of the array elements inside union() gives what I want

```julia
union(x[1],x[2])
---
Set(Symbol[:a, :b, :c])

```

However, to automate it, I tried list comprehension, but it did not work

```julia
union( [x[i] for i in 1:2] )
---
Set(Symbol[:a, :b, :c])
Set(Symbol[:c])

```

How can I use the list comprehension in a way that union gives one resulting set ?

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [September 16, 2020, 8:07pm UTC](https://discourse.julialang.org/t/using-union-and-list-comprehesions/46727/2 "2020-09-16T20:07:05Z")

</div>

> [@asavasci](#):
>
> ```julia
> x = [Set([:a,:b,:c]), Set([:c]) ]
> 
> ```

You can do

```julia
julia> union(x...)
Set{Symbol} with 3 elements:
  :a
  :b
  :c 

```

Using `...` is called “splatting”.

---

<div class="post-metadata">

**Author:** ![asavasci](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asavasci](https://discourse.julialang.org/u/asavasci)\
**Post date:** [September 16, 2020, 8:11pm UTC](https://discourse.julialang.org/t/using-union-and-list-comprehesions/46727/3 "2020-09-16T20:11:41Z")

</div>

It resolves, thanks.
