list interval index

dw dswj at plasa.com
Mon Jun 7 06:15:17 EDT 2004


What is the fastest python code to get the index of a huge
list of incrementing interval numbers, given a number?

ie:

>ic = [0,10,30,60,90,100,800,1000]
>print pyfuncsomething(ic,50)
2
>print pyfuncsomething(ic,500)
5

the slower code is like this:

def pyfuncsomething(ic,n):
     for i,el in enumerate(ic):
         if n > el:
                return i
     raise Exception, 'Not found'
thx

===========================================================================================
"Gabung INSTANIA, dapatkan XENIA. Daftar di www.telkomnetinstan.com, langsung dapat akses Internet Gratis..
Dan ..ikuti "Instan Smile" berhadiah Xenia,Tour S'pore, Komputer,dll, info hub : TELKOM Jatim 0-800-1-467826 "
===========================================================================================




More information about the Python-list mailing list