python如何搜索嵌套列表中的项目

Sha*_*kan 4 python nested list nested-lists

说我有这个清单:

li = [["0", "20", "ar"], ["20", "40", "asdasd"], ["50", "199", "bar"], ["24", "69", "sarkozy"]]
Run Code Online (Sandbox Code Playgroud)

现在,忘记数字,它们让我认识到字符串的位置.所以基本上,鉴于我手中有字符串"ar",如何提取包含"ar"的所有列表?

new_li = [["50", "199", "bar"], ["24", "69", "sarkozy"]]
Run Code Online (Sandbox Code Playgroud)

我怎样才能获得这个清单?

Ign*_*ams 11

>>> [x for x in li if 'ar' in x[2]]
[['0', '20', 'ar'], ['50', '199', 'bar'], ['24', '69', 'sarkozy']]
Run Code Online (Sandbox Code Playgroud)