Python data structure-set set

Source: Internet
Author: User
Tags pear set set

Original address: Http://docs.pythontab.com/python/python3.4/datastructures.html#tut-tuples

A collection is a set of unordered, non-repeating elements.

Basic features include relationship testing and elimination of duplicate elements. The collection object also supports mathematical operations such as Union (union), intersection (intersection), Difference (poor), and sysmmetric difference (symmetric difference sets).

Curly braces or set () functions can be used to create collections.

Note: To create an empty collection, you must use set () instead of {}. The latter is used to create an empty dictionary.

>>> Basket = {'Apple','Orange','Apple','Pear','Orange','Banana'}>>>Print(basket)#show that duplicates has been removed{'Orange','Banana','Pear','Apple'}>>>'Orange' inchBasket#Fast Membership TestingTrue>>>'Crabgrass' inchBasketfalse>>>#demonstrate set operations on the unique letters from the words...>>> A = set ('Abracadabra')>>> B = Set ('Alacazam')>>> A#unique letters in a{'a','R','b','C','D'}>>> A-B#letters in a and not in B{'R','D','b'}>>> A | B#letters in either A or B{'a','C','R','D','b','m','Z','L'}>>> A & B#letters in both A and B{'a','C'}>>> a ^ b#letters in A or B and not both{'R','D','b','m','Z','L'}

Python data structure-set set

Related Article

Contact Us

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.