私信  •  关注

nosklo

nosklo 最近创建的主题
nosklo 最近回复了
7 年前
回复了 nosklo 创建的主题 » 在python中删除多维数组中的重复值
yourlist = [
    [125.25,129,128,129],
    [124.25,127,130,131],
    [126,126,125,124],
    [126,124,130,124]
]
def seen(element, _cache=set()):
    result = element in _cache
    _cache.add(element)
    return result

filtered = ([x for x in sublist if not seen(x)] for sublist in yourlist)
filtered = [sublist for sublist in filtered if sublist] # filter out empty lists