Install versus python suite

What is the difference between set("a") and sets.Set("a") ? Their types are different, but they seem to do the same.

I can not find any resources on the Internet about this, but I have seen that both are used in the examples.

+5
source share
4 answers

You noted this Python 3, so the difference is that sets does not exist. Use set .

In Python 2, the difference is that sets deprecated. This is an old, slow, non-good version. Use set . This is explained in the documentation for the sets module , which appears instantly when searching for Python sets .

+11
source

The built-in set () was based on the old set.Set () sets and is faster.
Both do the same thing, although the sets module no longer exists in Python 3.

Here is the answer directly from the Python 2 library:
Types of built-in sets and phenisons have been developed based on lessons learned from the sets module. Key differences are:

Set and ImmutableSet have been renamed to set and frozenset.

- There is no equivalent to BaseSet. Use isinstance (x, (set, frozenset)) instead.

- The hash algorithm for built-in functions is much better (less collisions) for most datasets.

- Built-in versions have more space for brine.

- Embedded versions do not have union_update () method. Instead, use the update () method, which is equivalent.

- In embedded versions there is no _repr method (sorted = True). Instead, use the built-in repr () and sorted (): repr (sorted (s)) functions.

- The built-in version does not have a protocol for automatically converting to immutable. Many people find this feature confusing, and no one in the community has said that they found real opportunities for it.

+3
source

The set is now built-in and can be used without having to explicitly import the 'sets' module.

Link:

Python - cannot import Set from sets ("no module named sets" ")

0
source

There is not much difference, and you should use the built-in set or frozenset instead of the sets module.

In the module set itself, the documentation itself is -

Deprecated since version 2.6: the set / frozenset built-in types replace this module.

And there is no sets module in Python 3.x, only Python 2.

0
source

All Articles