Python: How do I 'pull' a list through a function
<p>I am trying to find the 'peak' in list of numbers. I tried the following;</p>

<pre><code>list = [5, 12, 34, 25, 13, 33]
n = range(len(list))
def func(n):
    if list[n] &gt;= list[n-1] and list[n] &gt;= list[n+1]:
        print list[n]
print func(n)
</code></pre>

<p>I get back the error 'list indices must be integers, not list'</p>

<p>you define n = range(...) so n = [0, 1,...] when you call func(n) and in your function:</p>

<pre><code>if list[n] &gt;= ....
</code></pre>

<p>becomes:</p>

<pre><code>if list[ [0, 1, ...] ] &gt;= ...
</code></pre>

<p>This is the reason why you get error 'list indices must be integers, not list'</p>

python python-2.7