为什么排序在 2 个列表上的工作方式不同? [关闭]

问题描述 投票:0回答:0

我有一个图片目录和一个图片描述目录(*.png 和 *.json)。图像文件名与 json 文件名相同。例如:

1676956467491_debug_finger.png  --- 1676956467491_debug_finger.json

之后,我创建了两个文件路径列表并对其进行了排序,总共11007个(图像和js)。

images = sorted(glob(os.path.join(raw_path, "*.png")))
js = sorted(glob(os.path.join(raw_path, "*.json")))
print(images[:3])
print(js[:3])
['../../data/lol/1676894633784_debug_finger.png', '../../data/lol/1676894634301_debug_finger.png', '../../data/lol/1676894634823_debug_finger.png', '../../data/lol/1676894635324_debug_finger.png']
['../../data/lol/1676894633784_debug_finger.json', '../../data/lol/1676894634301_debug_finger.json', '../../data/lol/1676894634823_debug_finger.json']
def check_equality_data(lst1: list, lst2: List) -> bool:
    lst1 = [i.split("/")[-1].split(".")[0] for i in images]
    lst2 = [j.split("/")[-1].split(".")[0] for j in js]
    intersection = set(images) & set(js)
    return True if len(intersection) == 0 else False

def draw_line(images: list, js: List) -> None:
    for i, j in tqdm(zip(images, js), total=len(images)):
        print(i,j)

if check_equality_data(images, js):
    draw_line(images, js)

奔跑:

../../data/lol/1676894633784_debug_finger.png ../../data/lol/1676894633784_debug_finger.json
../../data/lol/1676894634301_debug_finger.png ../../data/lol/1676894634301_debug_finger.json
../../data/lol/1676894634823_debug_finger.png ../../data/lol/1676894634823_debug_finger.json

../../data/lol/1676956481362_debug_finger.png ../../data/lol/1676956480828_debug_finger.json

这怎么可能?

我希望文件名相同

../../data/lol/1676894633784_debug_finger.png ../../data/lol/1676894633784_debug_finger.json
../../data/lol/1676894634301_debug_finger.png ../../data/lol/1676894634301_debug_finger.json
../../data/lol/1676894634823_debug_finger.png ../../data/lol/1676894634823_debug_finger.json

../../data/lol/1676956481362_debug_finger.png ../../data/lol/1676956481362_debug_finger.json
python list sorting set matcher
© www.soinside.com 2019 - 2024. All rights reserved.