Break up list into groups
James Stroud
jstroud at mbi.ucla.edu
Mon Jul 16 18:18:29 EDT 2007
James Stroud wrote:
> Here's how I *would* do it:
>
> py> def doit(alist):
> ... ary = []
> ... for i in alist:
> ... if 0xf0 & i:
> ... ary.append([i])
> ... else:
> ... ary[-1].append(i)
> ... return [x for x in ary if x]
> ...
To be absolutely compliant with the specifications, it should be
return [x for x in ary if len(x)>1]
in the recommended way. This does not affect the example given, though.
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