I'm trying to remove the lists from a list which have same first and third items but only keeping the first one. Example list and output:
li=[ [2,4,5], [1,3,5], [1,6,5] ]
output_list = [ [2,4,5], [1,3,5] ]
The code I've written takes a very long time to execute as the original list contains millions of list.
b_li = []
output_list = []
for x in li:
s = [ x[0], x[2] ]
if s not in b_li:
b_li.append(s)
output_list.append(x)
How can I improve the code? Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…