我已经浏览了列表上的很多问题,找不到要查找的内容。使用Python在迭代创建的嵌套列表中选择以上级别
我有一个大括号包装一些值和一些其他嵌套对包含值的大括号的字符串。我不知道该结构嵌套最深的层次,但它可能是这个样子:
{121 {12} 12 {211} 2}
我想遍历这个字符串,并将其转移到嵌套列表类似下面的伪代码的方式:
for i in thestring
if there is a leftbrace { start a new list inside the current list
elseif there is a rightbrace } close the current list and select the list on the level above
else add i to currently selected list
我不知道如何去建立一个列表级别,并关闭当前子表
你可能需要一个递归解析功能。 – TemporalWolf