我的问题与典型的问题不同。假设我们有,
X = ['123', '456', '789']
并且,我们想要查找 X 中是否有另一个列表具有完全相同的顺序。例如,
A = ['123', '456']
# should return True since A in X with same order
B = ['456', '123']
# should return False since elements in B are not in same order with X
C = ['123', '789']
# should return False since elements in C are not adjacent in X
谁能给我任何想法吗?
Python 2:
def is_a_in_x(A, X):
  for i in xrange(len(X) - len(A) + 1):
    if A == X[i:i+len(A)]: return True
  return False
Python 3:
def is_a_in_x(A, X):
  for i in range(len(X) - len(A) + 1):
    if A == X[i:i+len(A)]: return True
  return False
| 归档时间: | 
 | 
| 查看次数: | 3851 次 | 
| 最近记录: |