Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
165 views
in Technique[技术] by (71.8m points)

python列表去重

原始列表:
[[2,2,3],[2,3,2],[3,2,2],[7]]

去重后的列表:
[[2,2,3],[7]]

列表里的元素不分顺序,只是把重复的列表去掉,只保留一个
该如何做啊


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

只能做到这种程度了

?  ~ ipython
Python 3.7.4 (default, Sep  7 2019, 18:27:02)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: x = [[2,2,3],[2,3,2],[3,2,2],[7]]

In [2]: [list(_) for _ in set([tuple(sorted(__)) for __ in x])]
Out[2]: [[7], [2, 2, 3]]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...