Actually this should suffice `locations.get(w, []).append(i)`

Not sure if that is too clever, though.