Python code modifies loop while iterating over it
Doing this will pass a copy of the list for checking then modyfing the original list seperately:
for p in self._last_checkpoints[:]:
    if latest_save_path == self._CheckpointFilename(p):
        self._last_checkpoints.remove(p)
 can in be assigned this issue
 Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62492">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62492">No</a>

### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

The code is present on the master branch, but I found this bug by looking at the code, not from executing TensorFlow.

### Source

source

### TensorFlow version

master

### Custom code

No

### OS platform and distribution

_No response_

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

In tensorflow/python/training/saver.py, in _RecordLastCheckpoint:

```
# Remove first from list if the same name was used before.
for p in self._last_checkpoints:
  if latest_save_path == self._CheckpointFilename(p):
    self._last_checkpoints.remove(p)
```

This modifies the `_last_checkpoints` list while iterating over it, causing the loop to skip steps.

This seems like a bug, from looking at the code.

This should probably be something like:

```
self._last_checkpoints = [p for p in self._last_checkpoints if latest_save_path != self._CheckpointFilename(p)]
```

### Standalone code to reproduce the issue

```shell
Example program:


l = [1, 1, 1, 1, 1, 1, 1, 1]

for e in l:
	if e == 1:
		l.remove(e)

print(l)
```

Output

```
[1, 1, 1, 1]
```
```


### Relevant log output

_No response_