Move an existing element to the end (or beginning if last is false).
Raise KeyError if the element does not exist.