[BangPypers] string to list query

Nitin Kumar nitin.nitp at gmail.com
Thu Aug 5 08:11:15 CEST 2010


Below answer from Navin if good one, to make it more complex :) you can use

>>> z
'AT/CG'
>>> re.split('[A-Z]/[A-Z]',z)
['A', 'G']
>>> re.search('[A-Z]/[A-Z]',z).group()
'T/C'

using these two you can get your answer

On Thu, Aug 5, 2010 at 10:15 AM, Navin Kabra <navin.kabra at gmail.com> wrote:

> On Thu, Aug 5, 2010 at 10:07 AM, Vikram K <kpguy1975 at gmail.com> wrote:
>
> > Suppose i have this string:
> > z = 'AT/CG'
> >
> > How do i get this list:
> >
> > zlist = ['A','T/C','G']
> >
>
> This is a very poorly specified question. And in absence of any information
> about what exactly are the constraints on the input, and what is the
> difficulty you're trying to overcome (and indeed no information about what
> you tried already), I am going with the simplest solution:
>
> zlist = [z[0:1], z[1:4], z[4:5]]
>
> It looks like you're doing some DNA analysis, and I would guess that all
> these strings will be 5 characters, I'm sure my solution will work fine.
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>



-- 
Nitin K


More information about the BangPypers mailing list