Q:

python finding high value among slices of array

Below are snippets of code that is giving me some problems.  what i am trying to do is find every occurrence of a 356 day high. To do this i am trying code similar to the one below, but getting an exception on the "for i" line: 'builtin_function_or_method' object has no attribute 'getitem'
Quote = namedtuple("Quote", "Date Close Volume")

quotes = GetData() # arrray

    newHighs = []
    for i,q in range[365, len(quotes)]:  #<--Exception
        max = max(xrange[i-365, i].Close)  #<--i know this won't work, will fix when i get here
        if (q.Close > max):
            newHighs.append(i,q)

Any help on fixing this would be appreciated.  Also any tips on implementing this in an efficient manner (since quotes array currently has 17K elements) would also be nice.

A:

"Range" is a function. This means you use circle brackets, not square ones. This is the same deal with "xrange" in the line below. I understand why you'd think to use the square brackets, but what "range" does is create the list using those arguments. So it's not the same as when you want elements m to n of a list.

A:

range is a function that returns a generator (or list in python2). Thus, it must be called as a function range(365, len(quotes)), which will return all the numbers from 365 to len(quotes).
Square brackets imply indexing, like accessing items in a list. Since range is a function, not a list, it throws an exception when you try to access it.

