Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 嵌套列表循环_Python_List_Class_For Loop_If Statement - Fatal编程技术网

Python 嵌套列表循环

Python 嵌套列表循环,python,list,class,for-loop,if-statement,Python,List,Class,For Loop,If Statement,我想在下面的示例中循环嵌套列表['sally','joe'] data = ['joe','mike',['sally','joe'],'phil'] 我尝试了以下几点: for i in data: for j in (i): if type(j) == '<class '+"'list'>": print(j) 数据中的i的: 对于j in(i): 如果类型(j)=',则需要使用: if type(j) == list:

我想在下面的示例中循环嵌套列表
['sally','joe']

data = ['joe','mike',['sally','joe'],'phil']
我尝试了以下几点:

for i in data:
    for j in (i):
        if type(j) == '<class '+"'list'>":    
            print(j)
数据中的i的
:
对于j in(i):
如果类型(j)=',则需要使用:

if type(j) == list:
    print(j)

它当前不起作用,因为
type(j)
返回类类型的对象,而不是字符串。您可能会认为它是一个字符串,因为在REPL解释器中打印它时,您可能会看到
repr(..)
版本。

为什么不干脆
isinstance

for i in data:
    if isinstance(i,list):
        print(i)
现在输出为:

['sally', 'joe']

请显示您想要的输出。是
['sally','joe']
还是
乔•迈克•萨莉•乔•菲尔(中间有新行)?投票人:想评论一下吗?这个答案应该是“出了什么问题?”而不是“什么是正确的方法”。