Fixpoint all_but (i : nat) {A} (l : list A) : list A :=
match i with
O => tl l
| S i =>
match l with
nil => nil
| x :: l => x :: all_but i l
end
end.

Lemma permutation_all_but {A} i (l : list A) x :
nth_error l i = Some x ->
Permutation l (x :: all_but i l).