如何检测子列表中的逻辑和字符串索引并将其删除

Nek*_*eko 1 python algorithm types list python-3.x

我有一个这样的列表:

A = [[1,2,3,4],[1,1,2,4],[1,2,3,False],[1,False,2,3],[1,2,3,4],[1,2,3,'word'],[5,6,7,8],[1,4,3,4],[True,1,2,4],[0,1,0,1],[0,0,0,0],[False,False,False,False]]
Run Code Online (Sandbox Code Playgroud)

我希望输出像这样的列表:

A = [[1,2,3,4],[1,1,2,4],[1,2,3,4],[5,6,7,8],[1,4,3,4],[0,1,0,1],[0,0,0,0]]
Run Code Online (Sandbox Code Playgroud)

我只想删除或删除任何列表.它有字符串或逻辑的成员.我怎么做.

Wil*_*sem 5

我们可以使用列表推导来执行此操作,其中我们执行过滤器any(..)检查是否存在任何元素是str或的实例bool:

[sublist for sublist in A if not any(isinstance(e, (str, bool)) for e in sublist)]
Run Code Online (Sandbox Code Playgroud)

然后产生:

>>> [sublist for sublist in A if not any(isinstance(e, (str, bool)) for e in sublist)]
[[1, 2, 3, 4], [1, 1, 2, 4], [1, 2, 3, 4], [5, 6, 7, 8], [1, 4, 3, 4], [0, 1, 0, 1], [0, 0, 0, 0]]
Run Code Online (Sandbox Code Playgroud)