[英]How to remove items from a list on the SAME INDEX of duplicates i removed from another list
I have two lists of items, one for avatar names, and one for avatar pictures:我有两个项目列表,一个用于头像名称,一个用于头像图片:
name_list = ['name1', 'name2', 'name2', 'name3', 'name4', 'name5', 'name5']
picture_list = ['pic1', 'pic2', 'pic3', 'pic4', 'pic5', 'pic6', 'pic7']
I need each item from the name_list to always stay on the same index it shares with the item in the picture_list.我需要 name_list 中的每个项目始终保持在与 picture_list 中的项目共享的相同索引上。 So that when I remove the duplicates from the name_list, the items in the picture_list will be removed accordingly.
因此,当我从 name_list 中删除重复项时,picture_list 中的项目将相应地删除。 So that the result is:
所以结果是:
name_list = ['name1', 'name2', 'name3', 'name4', 'name5']
picture_list = ['pic1', 'pic2', 'pic4', 'pic5', 'pic6']
(It's important to mention that the numbers of the picture and the name don't have to be the same. only that they'll stay on the same index they shared before) (重要的是要提到图片的编号和名称不必相同。只是它们将保留在之前共享的同一索引上)
How may I do so in code?我如何在代码中这样做?
You might consider using nested lists.您可以考虑使用嵌套列表。 Consider the following:
考虑以下:
item_lists = [
['name1', 'pic1'],
['name2', 'pic2'],
# etc.
]
del item_lists[1]
This way you always keep the name and pictures together, and delete them simultaneously.这样您就可以始终将名称和图片放在一起,并同时删除它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.