Strange python error
<p>I am trying to write a python program that calculates a histogram, given a list of numbers like:</p>

<pre><code>1
3
2
3
4
5
3.2
4
2
2
</code></pre>

<p>so the input parameters are the filename and the number of intervals. </p>

<p>The program code is:</p>

<pre><code>#!/usr/bin/env python
import os, sys, re, string, array, math
import numpy

Lista = []

db = sys.argv[1] 
db_file = open(db,"r")
ic=0
nintervals= int(sys.argv[2])

while 1:
    line = db_file.readline()
    if not line:
        break
    ll=string.split(line)
    #print ll[6]
    Lista.insert(ic,float(ll[0]))
    ic=ic+1

lmin=min(Lista)
print "min= ",lmin
lmax=max(Lista)
print "max= ",lmax

width=666.666
width=(lmax-lmin)/nintervals
print "width= ",width

nelements=len(Lista)
print "nelements= ",nelements
print " "
Histogram = numpy.zeros(shape=(nintervals))

for item in Lista:
    #print item
    int_number = 1 + int((item-lmin)/width)
    print " "
    print "item,lmin= ",item,lmin
    print "(item-lmin)/width= ",(item-lmin)," / ",width," ====== ",(float(item)-float(lmin))/float(width)
    print "int((item-lmin)/width)= ",int((item-lmin)/width) 
    print item , " belongs to interval ", int_number, " which is from ", lmin+width*(int_number-1), " to ",lmin+width*int_number
    Histogram[int_number] = Histogram[int_number] + 1
</code></pre>

<p>4</p>

<p>but somehow I am completely lost, I get strange errors, can anybody help¿</p>

<p>Thanks</p>

<p>P.D. These are the results of the output:</p>

<pre><code>item,lmin=  1.0 1.0
(item-lmin)/width=  0.0  /  0.666666666667  ======  0.0
int((item-lmin)/width)=  0
1.0  belongs to interval  1  which is from  1.0  to  1.66666666667

item,lmin=  2.0 1.0
(item-lmin)/width=  1.0  /  0.666666666667  ======  1.5
int((item-lmin)/width)=  1
2.0  belongs to interval  2  which is from  1.66666666667  to  2.33333333333

item,lmin=  3.0 1.0
(item-lmin)/width=  2.0  /  0.666666666667  ======  3.0
int((item-lmin)/width)=  3
3.0  belongs to interval  4  which is from  3.0  to  3.66666666667
Traceback (most recent call last):
  File "from_list_to_histogram.py", line 43, in &lt;module&gt;
    Histogram[int_number] = Histogram[int_number] + 1
IndexError: index out of bounds
</code></pre>

<p>The most important errors are:</p>

<p>(item-lmin)/width=  1.0  /  0.666666666667  ======  1.5</p>

<p>and </p>

<p>IndexError: index out of bounds</p>
