如何删除彼此相关的2个重复项(PYTHON) [英] How can I remove duplication of 2 separate which is interrelated with each other (PYTHON)

查看:116
本文介绍了如何删除彼此相关的2个重复项(PYTHON)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读了很多标题后,我无法解决以下问题.有人能帮我吗?

After reading so many title, I couldn't solved the problem below. Does anyone can help me please ?

例如,我有两个相互关联的列表(list_I和list_II).

For instance, I have 2 list (list_I and list_II) which is interrelated with each other.

list_I = [123, 453, 444, 555, 123, 444]

list_II = [A, A, B, C, A, B]

我希望得到的是:

New_list_I = [123, 453, 444, 555]


New_list_II = [A , A, B, C]

我将这两个列表用作电子邮件的正文部分.这就是为什么我需要2个单独的列表(但相互关联)的原因.

I use these two list as a body part of e-mail. That's why I need 2 separate (but on the other hand interrelated) list.

我现在可以发送电子邮件.但是由于重复问题,它无法按我的意愿工作.

I'm able to send an e-mail right now. But because of the duplication problem it doesn't work how I want to.

P.S:我希望我能很好地说明问题,但是任何问题请不要犹豫,问我.

推荐答案

看起来很适合dict的工作:

list_I = [123, 453, 444, 555, 123, 444]    
list_II = ['A', 'A', 'B', 'C', 'A', 'B']

res = {}    
for elem, elem2 in zip(list_I, list_II):
    res[elem] = elem2    
print(res)

输出:

{123: 'A', 453: 'A', 444: 'B', 555: 'C'}

如果需要列表,可以将键和值与字典分开:

And if you want the lists, you can separate the keys and values from the dict:

print([k for k,v in res.items()])
print([v for k,v in res.items()])

输出:

[123, 453, 444, 555]
['A', 'A', 'B', 'C']

这篇关于如何删除彼此相关的2个重复项(PYTHON)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆