# IndexError: list index out of range

**Code:** `IndexError` · **Category:** Python · **Seen on:** Python

Code accessed a list position that doesn’t exist.

## Meaning

Lists are zero-based; the last index is len(x) - 1. Empty results, off-by-one loops and split() returning fewer parts than expected are typical.

## Common causes

- Empty list (no results)
- Off-by-one loop (range(len(x) + 1))
- line.split(',')[3] on a short line
- Modifying the list while iterating by index

## Quick fix

1. Check length before indexing
2. Iterate directly: for item in items
3. Use x[-1] for the last item
4. Guard: parts[3] if len(parts) > 3 else None

## Detailed fix by platform

### Python

1. `first = items[0] if items else None`

## How to diagnose

1. **Index** — Which index and list length?
2. **Data** — Why is the list shorter than expected?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/python/indexerror-list-index-out-of-range)
