一. 去重并保持原来元素的顺序
def dedupe(items): h = [] for item in items: if item not in h: # yield item h.append(item) return h #a = [1, 5, 2, 1, 9, 1, 5, 10] a = [ {'x':1, 'y':2}, {'x':1, 'y':3}, {'x':1, 'y':2}, {'x':2, 'y':4}] b = dedupe(a) print(b)
一. 去重并保持原来元素的顺序
def dedupe(items): h = [] for item in items: if item not in h: # yield item h.append(item) return h #a = [1, 5, 2, 1, 9, 1, 5, 10] a = [ {'x':1, 'y':2}, {'x':1, 'y':3}, {'x':1, 'y':2}, {'x':2, 'y':4}] b = dedupe(a) print(b)