简体   繁体   English

如何从我从另一个列表中删除的重复项的 SAME INDEX 上的列表中删除项目

[英]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.

相关问题 从列表中删除重复项并删除另一个列表中相同索引处的元素 - Remove duplicates from a list and remove elements at same index in another list 如何从列表中删除值并在同一索引处将其更改为另一个值? - How to remove the value from a list and change it at the same index with another value? 我试图基于另一个列表中的项目(在循环内)从列表中删除项目。 错误:列表索引超出范围 - I am trying to remove items from a list based upon items from another list (inside a loop). error: list index out of range 如何从列表中删除相对于另一个列表的重复项? - How to remove duplicates from a list with respect to another list? 如何从 Python 的对象列表中删除具有相同“标题”字段的重复项? - How to remove duplicates with the same 'title' field from object list in Python? 如何从列表中删除一个值,并从另一个列表中删除同一 position 中的值 - How do I remove a value from a list, and remove a value in the same position from another list 从列表中删除重复项 - Remove duplicates from the list 如何使用另一个列表作为参考从列表中的项目中删除字符 - how to remove characters from items in a list, using another list as reference 如何删除列表中的重复项并将其在另一个列表中的相应值(按索引位置)更改为平均值? - How can I remove duplicates in a list and change their corresponding values in another list (by index position) to the mean? 快速删除列表中的连续重复项和另一个列表中的相应项目 - Fast removal of consecutive duplicates in a list and corresponding items from another list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM