Logo

Programming-Idioms

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.
Implementation
Haskell

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Haskell implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import java.util.List;
items.remove(i);
items.delete_at(i) 
del items[i]
$removed_element = splice @items, $i, 1;
let new_list = items.filter(function(val,idx,ary) { return idx != i });
items.remove(i)
unset($items[$i]);
import std.algorithm.mutation;
items = items.remove(i);
items.removeAt(i);
list[i] := list[high(list)];
setlength(list,high(list));
List.delete_at(items, i)
items = append(items[:i], items[i+1:]...)
{Left, [_|Right]} = lists:split(I-1, Items),
Left ++ Right.
using System.Collections.Generic;
items.RemoveAt(i);
with Ada.Containers.Vectors;
use Ada.Containers;
Items.Delete (I);
local removedItem = table.remove(items,i)
copy(items[i:], items[i+1:])
items[len(items)-1] = nil
items = items[:len(items)-1]
(define (removeElementByIndex L i)
  (if (null? L)
      null
      (if (= i 0)
          (cdr L)
          (cons (car L) (removeElementByIndex (cdr L) (- i 1)))
       )
    )
)
items.erase (items.begin () + i);
items.splice(i,1);
integer, allocatable, dimension(:) :: items
items = [items(:i-1), items(i+1:)]
items.removeAt(i)
@import Foundation;
[items removeObjectAtIndex:i];
(defn remove-idx [i items]
    (keep-indexed #(when-not (= i %1) %2) items))
items removeAt: i.
items.pop(i)
import "slices"
items = slices.Delete(items, i, i+1)
val without = {
  val (left, right) = items.splitAt(i)
  left ++ right.drop(1)
}