【发布时间】:2017-02-16 19:32:30
【问题描述】:
我在列表中搜索了很多问题,但找不到我要找的东西。
我有一个字符串,其中包含一些值的大括号和一些包含值的其他嵌套大括号对。我不知道结构嵌套的最深层次,但它可能看起来像这样:
{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
我不知道如何上一级列表并关闭当前子列表
【问题讨论】:
-
你可能想要一个递归解析函数。
标签: python list python-3.x nested