<Python> リスト中の重複した要素を除く、、
リストlist
中の重複した要素duplicated element
を除く、、
set
を使うそうです。
例、、
In [1]: l = ['e', 'd', 'c', 'a', 'b', 'e', 'd'] In [2]: set(l) Out[2]: {'a', 'b', 'c', 'd', 'e'} In [3]: list(set(l)) Out[3]: ['c', 'a', 'b', 'd', 'e'] In [4]: sorted(list(set(l))) Out[4]: ['a', 'b', 'c', 'd', 'e'] In [5]: set? Init signature: set(self, /, *args, **kwargs) Docstring: set() -> new empty set object set(iterable) -> new set object Build an unordered collection of unique elements. Type: type
教えてもらいました。
www.lifewithpython.com