python题:有X,Y两个列表,写一程序完成X中的成员和Y中成员的匹配,返回匹配位置的首索引。

有X,Y两个列表,写一程序完成X中的成员和Y中成员的匹配,返回匹配位置的首索引。如
x=[1,2],y=[1,2,3,1,2]则显示0,3

x=[1,1],y=[1,1,1,1,2]则显示0,1,2

如无匹配,不显示。

>>> def result(x,y):
    tmp = [y[i:i+len(x)] for i in range(len(y)-len(x)+1)]
    return [i for i in range(len(tmp)) if x==tmp[i]]

>>> X=[1,2];Y=[1,2,3,1,2]
>>> result(X,Y)
[0, 3]
>>> X=[1,1];Y=[1,1,1,1,2]
>>> result(X,Y)
[0, 1, 2]
>>>