String Splitter Brain Teaser

James Stroud jstroud at mbi.ucla.edu
Sun Mar 27 20:46:33 EST 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