In article <[EMAIL PROTECTED]>,
James Stroud <[EMAIL PROTECTED]> 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
In article <[EMAIL PROTECTED]>,
James Stroud <[EMAIL PROTECTED]> 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
> That is clearer. At this point, though, you don't need the enumerator any
> more
> (so you can avoid indexing each item):
Good point.
>
> def xgen(s):
> srciter = iter(s)
> item = [srciter.next()]
> for i in srciter:
> if i == '/':
> item.append(srciter.
Michael Spencer wrote:
def xgen(s):
srciter = iter(s)
item = [srciter.next()]
for i in srciter:
if i == '/':
item.append(srciter.next())
else:
yield item
item = [i]
yield item
Note that the generator-based solution doesn't generate
Bill Mill wrote:
> [long genomes might justify a generator approach]
That's a good point. I should have said: *If* you are going to put the items
into a list anyway, then there is no point generating the list items individually.
Michael Spencer wrote:
>>[Bill's solution didn't work for multiple-
On Mon, 28 Mar 2005 09:18:38 -0800, Michael Spencer
<[EMAIL PROTECTED]> wrote:
> Bill Mill wrote:
>
> > for very long genomes he might want a generator:
> >
> > def xgen(s):
> > l = len(s) - 1
> > e = enumerate(s)
> > for i,c in e:
> > if i < l and s[i+1] == '/':
> >
Bill Mill wrote:
for very long genomes he might want a generator:
def xgen(s):
l = len(s) - 1
e = enumerate(s)
for i,c in e:
if i < l and s[i+1] == '/':
e.next()
i2, c2 = e.next()
yield [c, c2]
else:
yield [c]
for g in xge
On 28 Mar 2005 04:12:15 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> This is shorter:
> map(list,' '.join(s).replace(' / ','').split())
>
> but for very long genomes Michael Spencer's nice version can be faster.
>
for very long genomes he might want a generator:
def xgen(s):
l = le
This is shorter:
map(list,' '.join(s).replace(' / ','').split())
but for very long genomes Michael Spencer's nice version can be faster.
Hugs,
Bearophile
--
http://mail.python.org/mailman/listinfo/python-list
For the fans of funtional programming:
>>> s='ATT/GATA/G'
>>> [y.split('/') for y in (' '.join([x for x in s]).replace(' / ',
'/')).split()]
[['A'], ['T'], ['T', 'G'], ['A'], ['T'], ['A', 'G']]
--
http://mail.python.org/mailman/listinfo/python-list
Jp Calderone wrote:
On Sun, 27 Mar 2005 14:39:06 -0800, James Stroud <[EMAIL PROTECTED]> wrote:
"ATT/GATA/G"
gets split to
[['A'], ['T'], ['T', 'G'], ['A'], ['T'], ['A', 'G']]
I have written a very ugly function to do this (listed below for the curious),
but intuitively I think this should only ta
On Sun, 27 Mar 2005 14:39:06 -0800, James Stroud
<[EMAIL PROTECTED]> 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 th
Brian van den Broek wrote:
Much nicer than mine. =| :-)
^
|
(hats off)
Cool ascii art (but thanks for the translation)!
Michael
--
http://mail.python.org/mailman/listinfo/python-list
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.app
Michael Spencer said unto the world upon 2005-03-27 20:04:
James Stroud 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
s
James Stroud 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 lis
James Stroud said unto the world upon 2005-03-27 17:39:
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-degene
In article <[EMAIL PROTECTED]>,
James Stroud <[EMAIL PROTECTED]> 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
On Sun, 27 Mar 2005 14:39:06 -0800, James Stroud <[EMAIL PROTECTED]> 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
Using a parser may sound like overkill, but why not when it's this
easy? Get the latest pyparsing at http://pyparsing.sourceforge.net.
-- Paul
from pyparsing import oneOf, Group, OneOrMore, Literal
testdata = "ATT/GATA/G"
marker = oneOf( "A T G C")
SLASH = Literal("/").suppress()
genDegenList
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
21 matches
Mail list logo