Python-检查列表列表是否包含特定列表 [英] Python - Check if list of lists of lists contains a specific list

查看:75
本文介绍了Python-检查列表列表是否包含特定列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含其他列表的列表,这些列表的坐标为多个图块位置,并且我需要检查该列表是否包含另一个坐标列表,例如本例:

I have a list that contains other lists with coordinates for multiple tile positions and I need to check if that list contains another list of coordinates, like in this example:

totalList = [ [[0,1], [2,7], [6,3]], [[2,3], [6,1], [4,1]] ]

redList = [ [0,1], [2,7], [6,3] ]

if totalList contains redList:
   #do stuff

您能帮我看看如何做吗?

Can you please help me find out how to do this?

推荐答案

只需使用围堵测试:

if redList in totalList:

这将为您的示例数据返回True:

This returns True for your sample data:

>>> totalList = [ [[0,1], [2,7], [6,3]], [[2,3], [6,1], [4,1]] ]
>>> redList = [ [0,1], [2,7], [6,3] ]
>>> redList in totalList
True

这篇关于Python-检查列表列表是否包含特定列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆