On Thu, 5 Aug 2010 03:40:55 -0400 Sander Sweers <sander.swe...@gmail.com> wrote:
> On 5 August 2010 06:38, Vikram K <kpguy1...@gmail.com> wrote: > > Suppose i have this string: > > z = 'AT/CG' > > > > How do i get this list: > > > > zlist = ['A','T/C','G'] > > If you know the format of the string is always the same you can do > something like this. This fails when you have strings that do not have > the '/' in the middle and has 2 characters on either side. > > def parseString(s): > n = s.find('/') > l = [] > if n: > l = [s[0],s[n-1:n+2], s[-1]] > return l > > >>> parseString(s) > ['A', 'T/C', 'G'] > > Greets > Sander Much better than my original thought on this! If the data is stereotypic couldn't you simplify it though? ... z='AT/CG' zlist=[z[0],z[1:4],z[-1]] tom _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor