views:

73

answers:

2

say i have an output of this, i think its a list

['', 'AB-a-b-c-d', 'BC-f-c-a-r', 'CD-i-s-r']

i want to make the following:

['',[AB,a,b,c,d],[BC,f,c,a,r],[CD,i,s,r]]

or

['',[AB,BC,CD],[a,b,c,d],[f,c,a,r],[i,s,r]]
+1  A: 
newlist = [item.split("-") for item in oldlist]

or (this works better because the empty string is kept as is)

newlist = []
for item in oldlist:
    if not item:
        newlist.append(item)
    else:
        newlist.append(item.split("-"))
jcao219
i get the following:[[AB,e,r,t,y,],[BC,h,d,n,q],[CD,k,r,o]]how can i print only AB
babikar
`newlist[0][0]`
jcao219
A: 

I'll try to point you in the right direction rather than solve your homework for you: Try split and some for loops.

thegrinner