【发布时间】:2021-12-26 18:36:18
【问题描述】:
#sub list test 1
a = [1,1,2]
b = [0, 1,1,1,2,1]
#sub list test 2
c = [4,5]
d = [2,3,4,5,6]
if all(i in a for i in b):
print("Yes I have all the elements but not sure about their order :( ")
我已经尝试过all() 或使用collections 模块中的counter()。我似乎也无法弄清楚如何检查他们的订单。
【问题讨论】:
-
如果第一个元素匹配,还剩下什么要做?如果他们不这样做,还能做什么?
-
这能回答你的问题吗? Checking if list is a sublist
-
@sj95126 - 不,那里的解决方案不检查订单。您可以在上面的第一个测试中测试(a 和 b)
-
@Danny:该线程中有很多解决方案。有些不检查顺序,而 cmets 反映了这一点。
-
子列表已经暗示了相同的顺序。所以不清楚你在说什么。
标签: python