I think instead of this hacked backward lookup, you could remove ``linestyle`` from the argument list and call
``` python
line_segment.set_dashes(styles[i % len(styles)][1])
```