脑子不太好想记下点东西,主要实现的关键在于last_menu
和count1
,last_menu
存储进入下一个list之前li
的值,count1
存储进入下一个liist之前,li
的下一个位置的索引.
#!/bin/python3
# -*- coding:utf-8 -*-
li = ["1", '2', ["21", ["221", "222"], '23'], 3, 4]
count = 0
last_menu = []
count1 = []
while True:
if count > len(li) - 1:
if len(last_menu):
li = last_menu[-1]
last_menu.pop()
count = count1[-1]
count1.pop()
else:
break
if isinstance(li[count],list):
last_menu.append(li)
count1.append(count + 1)
li = li[count]
count = 0
continue
print(li[count])
count += 1
从百度进来的,博客不错哦!