Say I have a list,
l = [1, 2, 3, 4, 5, 6, 7, 8]
I want to grab the index of an arbitrary element and the values of its neighbors. For examp
The typical way to fit values to a certain range is to use the % operator:
%
k = l[(i + 1) % len(l)]