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

Idiom #29 Remove item from list, by its index

Remove i-th item from list items.
This will alter the original list or return a new list, depending on which is more idiomatic.
Note that in most languages, the smallest valid value for i is 0.

with Ada.Containers.Vectors;
use Ada.Containers;
Items.Delete (I);
using System.Collections.Generic;
items.RemoveAt(i);
import std.algorithm.mutation;
items = items.remove(i);
items.removeAt(i);
List.delete_at(items, i)
{Left, [_|Right]} = lists:split(I-1, Items),
Left ++ Right.
items = append(items[:i], items[i+1:]...)
copy(items[i:], items[i+1:])
items[len(items)-1] = nil
items = items[:len(items)-1]
take i items ++ drop (1 + i) items
new_list = items.filter(function(val,idx,ary) { return idx != i });
import java.util.List;
items.remove(i);
local removedItem = table.remove(items,i)
unset ($items[$i]);
list[i] := list[high(list)];
setlength(list,high(list));
# perl alters the original list with splice
$removed_element = splice @items, $i, 1;
del items[i]
items.delete_at(i) 
items.remove(i)

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

Idiom created by

programming-idioms.org

Related idioms