lists and sublists
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,开发者_StackOverflow中文版BC,CD],[a,b,c,d],[f,c,a,r],[i,s,r]]
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("-"))
I'll try to point you in the right direction rather than solve your homework for you: Try split and some for loops.
精彩评论