String Splitter Brain Teaser

Paul McGuire ptmcg at
Mon Mar 28 01:02:52 CEST 2005

Using a parser may sound like overkill, but why not when it's this
easy?  Get the latest pyparsing at

-- Paul

from pyparsing import oneOf, Group, OneOrMore, Literal

testdata = "ATT/GATA/G"

marker = oneOf( "A T G C")
SLASH = Literal("/").suppress()
genDegenList = OneOrMore( Group( marker + SLASH + marker ) | Group(
marker ) )

print genDegenList.parseString( testdata )

[['A'], ['T'], ['T', 'G'], ['A'], ['T'], ['A', 'G']]

More information about the Python-list mailing list