列表由一组元组组成,如果元组的第一个元素有重复,则删掉后面那个元组,并告知已出现。然后将列表里的元组转成字典。如下图所示
tuples=[("hmil999",82),("akim123",46),("hmil999",25)]
new_tuples=tuples[:]
for i in range(len(tuples)):
for k in range(len(tuples)):
#以下标判断,是否是后面出现
if tuples[i][0] == tuples[k][0] and i< k:
print("出现重复:",tuples[k])
new_tuples.pop(k)
#直接输出字典形式
print(dict(new_tuples))