2 回答
TA贡献1772条经验 获得超5个赞
看起来非常适合的工作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'}
如果你想要列表,你可以将键和值与字典分开:
print([k for k,v in res.items()])
print([v for k,v in res.items()])
输出:
[123, 453, 444, 555]
['A', 'A', 'B', 'C']
TA贡献1856条经验 获得超5个赞
list_I = [123, 453, 444, 555, 123, 444]
list_II = ['A', 'A', 'B', 'C', 'A', 'B']
New_list_I = []
New_list_II = []
for index, item in enumerate(list_I):
if item not in New_list_I:
New_list_I.append(item)
New_list_II.append(list_II[index])
print(New_list_I)
print(New_list_II)
输出:
[123, 453, 444, 555]
['A', 'A', 'B', 'C']
添加回答
举报