Python代码比较两个列表中的元素是否相等,并且返回相等元素的列表索引

list1 = [1,2,'a','b',5,67,78,99,"ji"]

list2 = [1,"a","b",2,87,34,67,"ji"]

for i in range(len(list1)):
    for j in range(len(list2)):
        if list1[i] == list2[j]:#元素相等时
            print("yes")
            print("i:",i)
            print("j:",j)
            print("\n")

        elif list1[i] != list2[j]:#元素不相等时
            print("no")
            print("s:",i)
            print("h:",j)

你可能感兴趣的:(Python)