String Splitter Brain Teaser
Doug Schwarz
see at sig.for.address.edu
Mon Mar 28 14:19:02 EST 2005
In article <mailman.925.1111963149.1799.python-list at python.org>,
James Stroud <jstroud at mbi.ucla.edu> wrote:
> Hello,
>
> I have strings represented as a combination of an alphabet (AGCT) and a an
> operator "/", that signifies degeneracy. I want to split these strings into
> lists of lists, where the degeneracies are members of the same list and
> non-degenerates are members of single item lists. An example will clarify
> this:
>
> "ATT/GATA/G"
>
> gets split to
>
> [['A'], ['T'], ['T', 'G'], ['A'], ['T'], ['A', 'G']]
How about this?
import re
s = "ATT/GATA/G"
result1 = re.findall(r"./.|.", s)
consensus = [c.split("/") for c in result1]
--
Doug Schwarz
dmschwarz&urgrad,rochester,edu
Make obvious changes to get real email address.
More information about the Python-list
mailing list