Concat

Concat

Concat[ expr1, expr2, ... ] joins lists and expressions into a single list.

Usages

Concat[ list1, list2, ... ]

Concat[ list1, list2, ... ] returns one list with all elements of list1, followed by all elements of list2, and so on. Duplicates are kept.

Example in out
Join three lists. Concat[ {1,2,3}, {4}, {4,5} ] {1, 2, 3, 4, 4, 5}

Concat[ expr1, expr2, ... ]

An argument that is not a list is added as a single element. Lists and other expressions can be mixed.

Example in out
Join numbers, expressions and a list. The expressions are not calculated. Concat[ 2, 3*4, {5,6,7+8} ] {2, 3*4, 5, 6, 7+8}
Join script variables. x := {1,2,3}
y := 4
z := {5}
r := Concat[x, y, z]
r = {1, 2, 3, 4, 5}
Build a list step by step, starting from an empty list. L := {}
L := Concat[L, 5]
L := Concat[L, 7]
L = {5, 7}
Details
  • Nested lists: only the outer list of each argument is removed. A list inside a list stays a list: Concat[ { {1,2},3}, 4, {5,6} ] returns { {1,2}, 3, 4, 5, 6}. To add a list as a single element, put it inside another list, such as { {1,2} }.
  • Empty lists add nothing: Concat[ {}, 1, {} ] returns {1}.
  • No arguments: Concat[] returns {}.

See also: ConstantArray, Length, RemoveI