Handling lists

James Stroud jstroud at mbi.ucla.edu
Sat Apr 23 17:13:05 EDT 2005


On Saturday 23 April 2005 12:50 pm, superprad at gmail.com wrote:
> I have a question on python lists.
> Suppose I have a 2D list
> list = [[10,11,12,13,14,78,79,80,81,300,301,308]]
> how do I convert it so that I arrange them into bins  .
> so If i hvae a set of consecutive numbers i would like to represent
> them as a range in the list with max and min val of the range alone.
> I shd get something like
> list = [[10,14],[78,81],[300,308]]



Here is an interesting way:

>>> a = iter([1,2,3,4])
>>> [(b,a.next()) for b in a]
[(1, 2), (3, 4)]

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list