I find this change really hard to read, perhaps the following is more readable: 

```
dimensions_index = lines.index('dimensions:\n')
variables_index = lines.index('variables:\n')
dimension_slice = slice(dimensions_index + 1, variables_index)

sort_key = lambda dimension_line: ('UNLIMITED' in dimension_line,
                                   dimension_line)

lines[dimension_slice] = sorted(lines[dimension_slice], key=sort_key)
```