这个问题最容易用伪代码来说明。我有一个像这样的列表:
linelist = ["a", "b", "", "c", "d", "e", "", "a"]
I would like to get it in the format:
questionchunks = [["a", "b"], ["c", "d", "e"], ["a"]]
我的第一次尝试是这样的:
questionchunks = []
qlist = []
for line in linelist:
if (line != "" and len(qlist) != 0 ):
questionchunks.append(qlist)
qlist = []
else:
qlist.append(line)
我的输出有点混乱。如果能给我一些指导,我将不胜感激。