在另一个路径列表文件中选择路径列表文件中的相同文件
choose same file in path list file in another path list file
我有一个路径文件列表
image_list1 = ['/content/gdrive/MyDrive/Match/bed/2.jpg','/content/gdrive/MyDrive/Match/bed/4.jpg']
和
image_list1=['/content/gdrive/MyDrive/Match/chairs/4.jpg','/content/gdrive/MyDrive/Match/chairs/3.jpg','/content/gdrive/MyDrive/Match/chairs/2.jpg','/content/gdrive/MyDrive/Match/chairs/1.jpg']
代码是什么我如何创建另一个列表,如这一行
image_list3=['/content/gdrive/MyDrive/Match/chairs/2.jpg','/content/gdrive/MyDrive/Match/chairs/4.jpg']
我有两张夹床和椅子吗?
尝试:
bed_list = [
"/content/gdrive/MyDrive/Match/bed/2.jpg",
"/content/gdrive/MyDrive/Match/bed/4.jpg",
]
chair_list = [
"/content/gdrive/MyDrive/Match/chairs/4.jpg",
"/content/gdrive/MyDrive/Match/chairs/3.jpg",
"/content/gdrive/MyDrive/Match/chairs/2.jpg",
"/content/gdrive/MyDrive/Match/chairs/1.jpg",
]
tmp = {i.rsplit("/", maxsplit=1)[-1] for i in bed_list}
out = [i for i in chair_list if i.rsplit("/", maxsplit=1)[-1] in tmp]
print(out)
打印:
[
"/content/gdrive/MyDrive/Match/chairs/4.jpg",
"/content/gdrive/MyDrive/Match/chairs/2.jpg",
]
我有一个路径文件列表
image_list1 = ['/content/gdrive/MyDrive/Match/bed/2.jpg','/content/gdrive/MyDrive/Match/bed/4.jpg']
和
image_list1=['/content/gdrive/MyDrive/Match/chairs/4.jpg','/content/gdrive/MyDrive/Match/chairs/3.jpg','/content/gdrive/MyDrive/Match/chairs/2.jpg','/content/gdrive/MyDrive/Match/chairs/1.jpg']
代码是什么我如何创建另一个列表,如这一行
image_list3=['/content/gdrive/MyDrive/Match/chairs/2.jpg','/content/gdrive/MyDrive/Match/chairs/4.jpg']
我有两张夹床和椅子吗?
尝试:
bed_list = [
"/content/gdrive/MyDrive/Match/bed/2.jpg",
"/content/gdrive/MyDrive/Match/bed/4.jpg",
]
chair_list = [
"/content/gdrive/MyDrive/Match/chairs/4.jpg",
"/content/gdrive/MyDrive/Match/chairs/3.jpg",
"/content/gdrive/MyDrive/Match/chairs/2.jpg",
"/content/gdrive/MyDrive/Match/chairs/1.jpg",
]
tmp = {i.rsplit("/", maxsplit=1)[-1] for i in bed_list}
out = [i for i in chair_list if i.rsplit("/", maxsplit=1)[-1] in tmp]
print(out)
打印:
[
"/content/gdrive/MyDrive/Match/chairs/4.jpg",
"/content/gdrive/MyDrive/Match/chairs/2.jpg",
]