def shift(key, array): counter = range(len(array)-1) new = counter for i in counter: new[i] = array[i-key] return new print shift(1, [5, 6, 7])