这是示例表单,稍后我将尝试用文字解释它。
我有一份分解字符串的清单......
say
[a, a, a, b, a, a, b, a, c, a, b, a, a, c, a, c, a]
其中 b 是标准 1,c 是标准 2
我想把它分成这样的列表:
[a, a, a, [b, a, a, [b, a, c], a, [b, a, a, c], a, c], a]
因此,我想处理该字符串,以便在浏览该字符串时,如果该项目与条件 1 匹配,则打开一个新列表,如果该项目与条件 2 匹配,则关闭该列表并返回上一级。
我尝试过做这样的事情,但效果不是很好。
def sublist(self, l):
for line in list:
if not b:
self.data.append(line)
else:
sublist(l[line:]) #<----- not sure how to recurse it.
我之前在 stackoverflow 上见过将列表分解为相同大小的列表,但没有使用一组标准分解为子列表。