Logo

Programming-Idioms

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

Idiom #226 Delete last element from list

Remove the last element from the list items.

import "slices"
items = slices.Delete(items, len(items)-1, len(items))
items = items[:len(items)-1]

If items is already empty, this will panic with "slice bounds out of range".
Warning: the last element still exists beyond len(items), thus it won't be garbage collected.
with Ada.Containers.Vectors;
Items.Delete_Last (Count => 1);

New implementation...
< >
programming-idioms.org