Lin*_* Ma 3 python set python-2.7
似乎在Python 2.7中不推荐使用集合,并想知道无序唯一集合的替代方案是什么?谢谢.
from sets import Set
a = Set()
a.add("1")
a.add("2")
a.add("3")
if "1" in a:
print "1"
if "Hello" in a:
print "Hello"
Run Code Online (Sandbox Code Playgroud)
问候,林
集合仍然在python 2.7中可用,并且内置.
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a_set = set([1, 2, 3])
>>> a_set
set([1, 2, 3])
>>> b_set = {1, 2, 3}
>>> b_set
set([1, 2, 3])
Run Code Online (Sandbox Code Playgroud)
文档:https://docs.python.org/2/library/sets.html 并查看页面顶部的通知:
从2.6版开始不推荐使用:内置的set/frozenset类型替换了这个模块.