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.

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

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

Idiom created by

Related idioms