String Splitter Brain Teaser

James Stroud jstroud at mbi.ucla.edu
Mon Mar 28 03:46:33 CEST 2005


On Sunday 27 March 2005 05:04 pm, Michael Spencer wrote:
>   >>> def group(src):
>   ...     stack = []
>   ...     srciter = iter(src)
>   ...     for i in srciter:
>   ...         if i == "/":
>   ...             stack[-1].append(srciter.next())
>   ...         else:
>   ...             stack.append([i])
>   ...     return stack

Very pretty:

group("AGC/C/TGA/T")
[['A'], ['G'], ['C', 'C', 'T'], ['G'], ['A', 'T']]


-- 
James Stroud, Ph.D.
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