我需要检查list1是否是list2的子列表(True;如果list2中与list1相同的每个整数与list1中的索引顺序相同)
def sublist(lst1,lst2):
for i in range(len(lst1)):
if lst1[i] not in lst2:
return False
for j in range(len(lst2)):
if (lst1[j] in lst2) and (lst2.index(lst1[i+1]) > lst2.index(lst1[i])):
return True
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我......为什么这不起作用?
pets = ['boa', 'cat', 'dog']
for pet in pets:
print(pet)
boa
cat
dog
>>> for pet in pets:
print(pet, end=', ')
boa, cat, dog,
>>> for pet in pets:
print(pet, end='!!! ')
boa!!! cat!!! dog!!!
Run Code Online (Sandbox Code Playgroud)
但是怎么样?我试图用sep替换end但是什么都没发生但是我知道sep在打印时用于separete,我如何以及何时可以使用sep?sep和end之间有什么区别?