I\'m trying to learn python and I was trying to write something simple. I am developing under Pydev (Eclipse) using OS X 10.8. I installed python 3.2 using the 64bits .dmg i
You don't need the sets
module anymore. set is a built-in class in Python 3 and can be used without import.
my_set = set()
you don't need to use
from sets import Set
engineers = Set(['John', 'Jane', 'Jack', 'Janice'])
above is Deprecated since version 2.6:
you can use below code above 2.6 version
engineers = set(['John', 'Jane', 'Jack', 'Janice'])
programmers = set(['Jack', 'Sam', 'Susan', 'Janice'])
managers = set(['Jane', 'Jack', 'Susan', 'Zack'])
employees = engineers | programmers | managers
print(employees)
In every recent python version sets are builtin as set
and Python 3 got rid of the deprecated sets
module altogether.
If you wanted to ensure that the code also works with ancient versions you could do something like this though:
try:
set
except NameError:
from sets import Set as set
If you need to run old code and don't want to change it (bad!):
try:
from sets import Set
except ImportError:
Set = set