Go 遍历slice时,删除值
func TestRunningRemove(t *testing.T) {
list := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
t.Logf("prev: %v", list)
for i := 0; i < len(list); {
if list[i]%2 == 0 {
list = append(list[:i], list[i+1:]...)
} else {
i += 1
}
}
t.Logf("after: %v", list)
}