这可能是一个愚蠢的问题,但是有可能检查tuple1中的元素是否是与tuple1中出现的相同序列中的另一个tuple2 的子集?我尝试用.issubset来做这个,但这不会看tuple1的序列是否在元组2中:
tuple1 = ([1, 2, 3])
tuple2 = ([1, 2, 3, 4, 5])
set(tuple1).issubset(tuple2)
True
tuple1 = ([1, 2, 3])
tuple2 = ([1, 3, 2, 4, 5])
set(tuple1).issubset(tuple2)
True # Only membership is considered, not sequence
我想要的是:
tuple1 = ([1, 2, 3])
tuple2 = ([1, 2, 3, 4, 5])
(tuple1).sequenceisin(tuple2)
True
tuple1 = ([1, 2, 3])
tuple2 = ([1, 3, 2, 4, 5])
(tuple1).sequenceisin(tuple2)
False
有一种简单的方法吗?