RemoveI
RemoveI
RemoveI[ indices, list ] returns a copy of a list with the elements at the given positions removed.
RemoveI[ {i1, i2, ...}, list ]
RemoveI[ {i1, i2, ...}, list ] returns a new list with the elements of list, except those at positions i1, i2, ... (the first position is 1). Note that the positions come first and the list second. The order of the indices does not matter.
| Example | in | out |
|---|---|---|
Remove the elements at positions 1 and 3. |
RemoveI[ {1,3}, {a,b,c,d} ] |
{b, d} |
| The same element is removed only once, even if its position is given twice. | RemoveI[ {3,1,3}, {a,b,c,d} ] |
{b, d} |
Remove the first 3, using the position found by FindI. |
L := {7, 3, 9, 3} |
I = {2}r = {7, 9, 3} |
RemoveI[ i, list ]
A single position can also be given without a list.
| Example | in | out |
|---|---|---|
Remove the element at position 2. |
RemoveI[ 2, {a,b,c,d} ] |
{a, c, d} |
Remove the largest value, using the position found by MaxI. |
L := {7, 3, 9} |
r = {7, 3} |
- Empty lists:
RemoveI[ {}, {a,b,c,d} ]returns{a, b, c, d}andRemoveI[ {1,2}, {} ]returns{}.
| Invalid input | Result |
|---|---|
RemoveI[ {1}, a ] |
Left unevaluated: the result is RemoveI[ {1}, a ] itself. The second argument must be a list. |
RemoveI[ {1} ] |
Left unevaluated: RemoveI takes exactly two arguments. |
Invalid positions are ignored without an error. Positions that are 0, negative, larger than the length of the list or not an integer do not remove anything: RemoveI[ {0,5,-1}, {a,b,c,d} ] returns {a, b, c, d} and RemoveI[ {1.5, 2}, {a,b,c,d} ] only removes position 2. If the first argument is not a number or a list, such as RemoveI[ x, {a,b,c,d} ], the whole list is returned unchanged.
See also: Difference, FindI, MaxI, MinI