Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #227 Copy list

Create new list y containing the same elements as list x.

Subsequent modifications of y must not affect x (except for the contents referenced by the elements themselves if they contain pointers).

y = x[:]
List<T> y = x.ToList();
List<Int32> y = new List<Int32>(x);
y := make([]T, len(x))
copy(y, x)
let y = x.slice();
classes
  y.assign(x);
y = x.dup

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org