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>Your issue is that you're trying to pass a range as an argument. Range(len(list)), in this case, is going to give you this list: [0,1,2,3,4,5]</p>

<p>Your function is expecting a single number, but you're passing a list. To check every number, change this line:</p>

<pre><code> print(func(n))
</code></pre>

<p>to this:</p>

<pre><code>for number in n:
    print(func(number))
</code></pre>

python python-2.7