Symmetric difference Surprised that we don't have a symmetric difference challenge yet.

Given two lists only containing positive integers, return all items among these two lists that aren't contained in both of the lists.

Rules

From the set definition:


  A set is a collection of definite distinct items.



So you can assume the items in the input lists are always unique.
You can also take input as a set if your language supports it.


Test cases

Here is a sample program that generates the test cases.

[1,2,3],[2,3,4] -&gt; [1,4]
APL (Dyalog Unicode), 3 bytes



∪~∩


Try it online!

How it works

∪~∩  ⍝ Input: two sets as vectors
∪    ⍝ Set union
 ~   ⍝ Set minus
  ∩  ⍝ Set intersection




The rest is just for fun.

APL (Dyalog Unicode), 4 bytes



~∪~⍨


Try it online!

~∪~⍨
~     ⍝ Set difference (a~b)
 ∪    ⍝ Set union
  ~⍨  ⍝ Set difference reversed (b~a)


APL (Dyalog Unicode), 5 bytes



~⍨∪⍨~


Try it online!

This one is palindromic!

How it works

~⍨∪⍨~
~⍨     ⍝ Set difference reversed (b~a)
  ∪⍨   ⍝ Set union reversed
    ~  ⍝ Set difference (a~b)