Try this: >>> def f(mystring): charlist = list(mystring) tmplist = [ [''] ] for a in charlist: if tmplist[-1][-1] == '/' or a == '/': tmplist[-1].append(a) else: tmplist.append( [a] ) return [''.join(a) for a in tmplist][1:]
>>> #Thusly: >>> f('AT/CG') ['A', 'T/C', 'G'] >>> f('CATAT/T/CATA/C/AC/TACGAA/AGT/GGTC/GGGTCTACGATTT/A/A/GC/CCCCT/GA/C/A/T/GA/G/C/ACAAG/CC/GAGGTG/GACTCA/G/TTT/TAGT/AGAC/AT/CC/GG/CG/G/A') ['C', 'A', 'T', 'A', 'T/T/C', 'A', 'T', 'A/C/A', 'C/T', 'A', 'C', 'G', 'A', 'A/A', 'G', 'T/G', 'G', 'T', 'C/G', 'G', 'G', 'T', 'C', 'T', 'A', 'C', 'G', 'A', 'T', 'T', 'T/A/A/G', 'C/C', 'C', 'C', 'C', 'T/G', 'A/C/A/T/G', 'A/G/C/A', 'C', 'A', 'A', 'G/C', 'C/G', 'A', 'G', 'G', 'T', 'G/G', 'A', 'C', 'T', 'C', 'A/G/T', 'T', 'T/T', 'A', 'G', 'T/A', 'G', 'A', 'C/A', 'T/C', 'C/G', 'G/C', 'G/G/A'] --- En date de : Mer, 4.8.10, Vikram K <kpguy1...@gmail.com> a écrit : De : Vikram K <kpguy1...@gmail.com> Objet : [Tutor] string to list À : tutor@python.org Date: mercredi 4 août 2010 21 h 38 Suppose i have this string: z = 'AT/CG' How do i get this list: zlist = ['A','T/C','G'] -----La pièce jointe associée suit----- _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor