开发者

Accessing later index in array using enumerate(array) Python

开发者 https://www.devze.com 2023-01-12 10:21 出处:网络
开发者_运维知识库hey guys, how would you access an array from array[n] in an array of 100 floats in this for loop (i need the enumerate):
开发者_运维知识库

hey guys, how would you access an array from array[n] in an array of 100 floats in this for loop (i need the enumerate):

for index,value in enumerate(array):
    #do stuff with array[n]
    n=n+1

im trying to make it so that it operates in a smaller and smaller space each iteration..

thanks


You should probably clarify whether you mean a list, a numpy array, an array.array, or something else...

That having been said, it sounds like you want to slice whatever your "array" is. Perhaps something like this?:

data = range(10)
for i in range(len(data)):
    print data[i:]

Which would output:

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[2, 3, 4, 5, 6, 7, 8, 9]
[3, 4, 5, 6, 7, 8, 9]
[4, 5, 6, 7, 8, 9]
[5, 6, 7, 8, 9]
[6, 7, 8, 9]
[7, 8, 9]
[8, 9]
[9]

Hope that helps a bit, anyway...


lst = range(10)

for n, N in enumerate(lst):
    print lst[n:]
0

精彩评论

暂无评论...
验证码 换一张
取 消