# Python enumerate, zip and range: loop with an index or two lists

Published: 2026-11-30
Updated: 2026-12-01

Rights: original
Source: https://kairos-2z6s.onrender.com/res/python-enumerate-zip-range-full-en
`enumerate` adds indexes, `zip` pairs iterables, `range` generates numbers. zip stops at the shortest; range excludes its stop; enumerate takes a start.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 3 tests were run, TE-53-A, TE-53-B and TE-53-C. The expected non-zero exit is TE-53-C (exit status 1). Every row has a recorded log in the evidence archive. The evidence table lists the exit status and log hash of every row, and no Exit status line on this page is for the A row.)

### TE-53-A: zip stops at the shortest iterable, range excludes stop, enumerate accepts a start

No setup needed: the command below creates what it uses in the throwaway folder.

Command:

```bash
python3 -c "print(list(zip([1,2,3],'ab')), list(range(1,4)), list(enumerate('ab', start=1)))"
```

Recorded output:

```
[(1, 'a'), (2, 'b')] [1, 2, 3] [(1, 'a'), (2, 'b')]
```

### TE-53-B: zip of two strings, range with a negative step, and enumerate of an empty list

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
cat > s.py <<'EOS'
print(list(zip('ab', 'xyz')))
print(list(range(5, 0, -2)))
print(list(enumerate([])))
EOS
```

Command:

```bash
python3 s.py
```

Recorded output:

```
[('a', 'x'), ('b', 'y')]
[5, 3, 1]
[]
```

Exit status: 0. This status and the output match what was written before the run.

### TE-53-C: expected non-zero exit: range with a float raises TypeError

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
cat > s.py <<'EOS'
range(1.5)
EOS
```

Command:

```bash
python3 s.py
```

Recorded output: none, standard output was empty.

Standard error from the same run:

```
Traceback (most recent call last):
  File "/tmp/b21-ou58rtkn/work/s.py", line 1, in <module>
    range(1.5)
TypeError: 'float' object cannot be interpreted as an integer
```

Exit status: 1. This status and the output match what was written before the run. The path in the traceback line is a temporary folder and differs on each machine and each run.

TE-53-B: zip of 'ab' and 'xyz' stopped at the shorter input, range(5, 0, -2) gave [5, 3, 1], and enumerate of an empty list gave []. TE-53-C: range(1.5) stopped with exit status 1. The last line of standard error is TypeError: 'float' object cannot be interpreted as an integer.

## Limits

zip stops at the shortest; range excludes its stop; enumerate takes a start.

## Source

- https://docs.python.org/3/library/functions.html

## Evidence

- `TE-53-A`: zip stops at the shortest iterable, range excludes stop, enumerate accepts a start

- logs: one recorded log for each row above
- Recorded on: Linux x86_64, kernel 7.3.4; bash 5.1.16; git 2.34.1; python 3.10.12; findutils 4.8.0; grep 3.7; sed 4.8; gawk 5.1.0; tar 1.34; curl 7.81.0. Locale C.UTF-8, TZ=UTC.

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-53-A` | zip stops at the shortest iterable, range excludes stop, enumerate accepts a start | 0 | PASS | `944bc21dffb2` |
| `TE-53-B` | zip of two strings, range with a negative step, and enumerate of an empty list | 0 | PASS | `a4cc79ad7659` |
| `TE-53-C` | expected non-zero exit: range with a float raises TypeError | 1 | PASS | `9251caf79948` |

Every row has a recorded log holding the setup commands, the command, stdout, stderr, exit status and the final directory state. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [Python subprocess.run: run a command, read output and exit code](https://kairos-2z6s.onrender.com/res/python-subprocess-full-en)
- [Python comprehensions: build a list, dict or set in one line](https://kairos-2z6s.onrender.com/res/python-comprehensions-full-en)
- [Python: write, append and read a text file](https://kairos-2z6s.onrender.com/res/python-files-full-en)
- [Python dict.get: read a key without KeyError](https://kairos-2z6s.onrender.com/res/python-dict-get-full-en)
- [Python f-strings: expressions and format specs](https://kairos-2z6s.onrender.com/res/python-functions-fstrings-full-en)
