# Six Methods of integration in the Python dictionary

Source: Internet
Author: User

If you are confused about the actual application steps of the collection type in the Python dictionary, or are interested in the opposite, you can browse our articles, not only can you solve your problem, it can also stimulate your interest in the Python dictionary computer language.

Set Type

① Set () and frozenset () using the factory method of the set ():

```

>>> s = set('cheeseshop')

>>> s

set(['c', 'e', 'h', 'o', 'p', 's'])

>>> t = frozenset('bookshop')

>>> t

frozenset(['b', 'h', 'k', 'o', 'p', 's'])

>>> type(s)

<type 'set'>

>>> type(t)

<type 'frozenset'>

```

② How to update a set and use the built-in methods and operators of various sets to add and delete members of the Set:

```

>>> s

set(['c', 'e', 'h', 'o', 'p', 's', 'z'])

>>> s.update('pypi')

>>> s

set(['c', 'e', 'i', 'h', 'o', 'p', 's', 'y', 'z'])

>>> s.remove('z')

>>> s

set(['c', 'e', 'i', 'h', 'o', 'p', 's', 'y'])

>>> s -= set('pypi')

>>> s

set(['c', 'e', 'h', 'o', 's'])

```

③ Delete a set

```

del s

```

④ Member relationship (in, not in)

```

>>> s = set('cheeseshop')

>>> t = frozenset('bookshop')

>>> 'k' in s

False

>>> 'k' in t

True

>>> 'c' not in t

True

```

⑤ Set equivalence/non-equivalence

```

>>> s == t

False

>>> s != t

True

>>> u = frozenset(s)

>>> s == u

True

>>> set('posh') == set('shop')

True

```

⑥ Differential or relative complementary set (-) of the difference or relative complementary set of the Two sets (s and t) refers to a set C, the elements in the set, only belongs to the set s, not
In set t. The difference symbol has an equivalent method,

```

difference().

>>> s - t

set(['c', 'e'])

```

Symmetric Difference (^): symmetric difference is the XOR of the set. The above article describes the practical application steps of the Python dictionary for the set type.

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.