你知道,转一下清单:
a = ["hello", "hello", "hi", "hi", "hey"]
Run Code Online (Sandbox Code Playgroud)
进入清单:
b = ["hello", "hi", "hey"]
Run Code Online (Sandbox Code Playgroud)
你只需这样做:
b = list(set(a))
Run Code Online (Sandbox Code Playgroud)
这是快速和pythonic.
但是,如果我需要打开这个列表怎么办:
a = [["hello", "hi"], ["hello", "hi"], ["how", "what"], ["hello", "hi"],
["how", "what"]]
Run Code Online (Sandbox Code Playgroud)
至:
b = [["hello", "hi"], ["how", "what"]]
Run Code Online (Sandbox Code Playgroud)
什么是pythonic方式呢?
jam*_*lak 14
>>> a = [["hello", "hi"], ["hello", "hi"], ["how", "what"], ["hello", "hi"], ["how", "what"]]
>>> set(map(tuple, a))
set([('how', 'what'), ('hello', 'hi')])
Run Code Online (Sandbox Code Playgroud)