I am trying to create a function that always returns me a pre-fixed number of elements from an array that will be larger than the prefix number:
def getElements(i,arr,size=10): return cyclic array return
where i denotes the index of the array to extract and arr represents the array of all elements:
Example:
a = [0,1,2,3,4,5,6,7,8,9,10,11] b = getElements(9,a) >> b >> [9,10,11,0,1,2,3,4,5,6] b = getElements(1,a) >> b >> [1,2,3,4,5,6,7,8,9,10]
where i = 9 and the array returns [9:11]+[0:7] to complete 10 elements with i = 1 do not need to loop the array, just get [1:11]
thanks for the help
Source code (doesn't work):
def getElements(i,arr,size=10): total = len(arr) start = i%total end = start+size return arr[start:end]
EDIT:
I can not do import for this script