Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 检查python列表中的顺序和值等效性_Python 3.x_Database_List_Format - Fatal编程技术网

Python 3.x 检查python列表中的顺序和值等效性

Python 3.x 检查python列表中的顺序和值等效性,python-3.x,database,list,format,Python 3.x,Database,List,Format,如果两个数字在一个列表中的顺序相同,它将打印出该数字的顺序和数字本身。因此在list_1和list_221是这两个列表中的第三个值,因此结果:number:24顺序:3 list_1 =[27, 20, 22, 21, 17, 12, 24, 23, 19, 14, 11, 26, 25, 13, 15, 21, 18, 28, 29, 10] list_2 = [14, 25, 26, 21, 22, 17, 11, 23, 27, 18, 24, 28, 12, 29, 16, 19, 13

如果两个数字在一个列表中的顺序相同,它将打印出该数字的顺序和数字本身。因此在
list_1
list_2
21是这两个列表中的第三个值,因此结果:
number:24顺序:3

list_1 =[27, 20, 22, 21, 17, 12, 24, 23, 19, 14, 11, 26, 25, 13, 15, 21, 18, 28, 29, 10]
list_2 = [14, 25, 26, 21, 22, 17, 11, 23, 27, 18, 24, 28, 12, 29, 16, 19, 13, 10, 20, 15]

您可以将它们一起迭代:

for i, j in zip(enumerate(list_1), enumerate(list_2)):
    if i == j:
        print("number:{} order:{}".format(i[1], i[0]))

@selcuk egese,请先尝试以下步骤: 然后看看你是否能找到它-通过循环找到第一个匹配

lst1_-map={i:x代表i,x在枚举(列表_-1)}
打印(lst1_地图)
lst2_map={i:x代表i,x在枚举(列表_2)}
打印(lst2_地图)

您可以使用zip函数执行此操作,并创建如下对象:

[(list_1[0], list_2[0]), (list_1[1], list_2[1]), etc]
然后,您可以迭代该对象,并验证每个元组中的每个项是否相等。比如:

 for index, ziped in enumerate(zip(list_1, list_2)):
     if ziped[0] == ziped[1]:
         print(f"number: {ziped[0]} order {index}")

enumerate()函数仅用于检索订单。

问题是否已解决?如果是,请将任何答案标记为已接受。