I have a list of numbers, and for each value in the list, I need to compute something based off of that value and the previous 7 values. I'm sure there is an easy bit of code to do this, but I am just at a loss right now. For each values in the list, how can I pull out that value and the previous 7 values?

Here two ways:

import random
stuff = random.sample(range(10,1000,10), 20)
print 'data: ', stuff
print 'groups'
for end in range(7, len(stuff)):
    print stuff[end-7:end]

print 'more efficient'
seven = stuff[:7]
for end in range(7, len(stuff)):
    print seven
    del seven[0]
    seven.append(stuff[end])
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.