Python3在所有列表和元组上循环

Python3在所有列表和元组上循环,python,for-loop,python-3.x,dictionary,Python,For Loop,Python 3.x,Dictionary,假设我有一个包含多个列表和元组的字典,我想循环字典的所有项,也要循环字典的所有元组和列表(以便只获取值和关键字),除了定义一组for循环,还有其他方法吗 即: 旁白:type(arg)=list或tuple并不像我认为的那样。请阅读的答案以获得解释。 def islist(arg): if type(arg) == list or tuple: #loop for i in arg: if type(i) == list or tu

假设我有一个包含多个列表和元组的字典,我想循环字典的所有项,也要循环字典的所有元组和列表(以便只获取值和关键字),除了定义一组for循环,还有其他方法吗

即:

旁白:
type(arg)=list或tuple
并不像我认为的那样。请阅读的答案以获得解释。
def islist(arg):
    if type(arg) == list or tuple:
        #loop
        for i in arg:
            if type(i) == list or tuple:
                #again
                for i in arg:
                    if type(i) == list or tuple:
                        #again