Hi All,

    this should be a very easy question but I am trying to make a
script run as fast as possible, so please bear with me if the solution
is easy and I just overlooked it.

I have a list of integers, like this one:

indices = [1,2,3,4,5,6,7,8,9,255,256,257,258,10001,10002,10003,10004]

>From this list, I would like to find out which values are consecutive
and store them in another list of tuples (begin_consecutive,
end_consecutive) or a simple list: as an example, the previous list
will become:

new_list = [(1, 9), (255, 258), (10001, 10004)]

I can do it with for loops, but I am trying to speed up a fotran-based
routine which I wrap with f2py (ideally I would like to do this step
in Fortran too, so if you have a suggestion on how to do it also in
Fortran it would be more than welcome). Do you have any suggestions?

Thank you for your time.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
http://thedoomedcity.blogspot.com/
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to