python - Remove duplicates and finding unique sublists -
this question has answer here:
i have nested list looks this:
lst = [[1,2,3],[1,2],[1,2,3],[2,3],[4,5],[2,3],[2,4],[4,2]] i find unique sublists in lst. using above example, i'd find:
lst_set = [1,2,3],[1,2],[2,3],[4,5],[2,4]] order not matter. in otherwords, [2,4] , [4,2] same.
in [22]: lst = [[1,2,3],[1,2],[1,2,3],[2,3],[4,5],[2,3],[2,4],[4,2]] in [23]: set(frozenset(item) item in lst) out[23]: set([frozenset([2, 4]), frozenset([1, 2]), frozenset([2, 3]), frozenset([1, 2, 3]), frozenset([4, 5])])
Comments
Post a Comment