That's a neat trick, I didn't know about `.setdefault` before. But because you are modifying l after you get it anyways, I would write this as

```python
l = locations.get(w, [])
l.append(i)
locations[w] = l
```

or maybe, if I was feeling clever

```python
locations[w] = locations.get(w, []) + [i]
```