python3.6 Collection Notes (i)

Source: Internet
Author: User

slowly realize that in learning or solving a problem, the first to try to understand the problem itself involves the relevant concepts,

To further analyze and solve the specific problems, you can do more with less.

For example, for a set problem in a programming language, take the Python language as an example (in this way review something about the collection itself).

And the collection itself in the field of mathematics has unparalleled special importance. The classification of the collections in the Mathematics discipline is:

Empty set

There is a special kind of collection that does not contain any Elements , such as {X|x∈r x2+1=0}, is called Empty Set , remember ? ;

Subset

set S,T is a set of two, if all elements of s belong to T, that is is called S is T's subset , recorded as ;

Equal

If the elements of the two set S and T are identical, then the S is equal to the T two set, which is recorded as s=t;

and set

A collection of all elements that belong to set a or that belong to set B, as A∪b (or b∪a), read as "A and B"

(or "B and A"), i.e. A∪b={x|x∈a, or x∈b}. and more and more;

Intersection

A set of identical elements belonging to A and B, recorded as A∩B (or b∩a), read as "a cross B"

(or "B-cross A"), i.e. A∩b={x|x∈a, and x∈b}. The intersection is more and more small;

Complement set

Relative complement set: a set of elements belonging to a and not belonging to B, known as a relative complement to a, as a-B or a\b;

Absolute complement: a about the relative complement of a complete set of U is called a absolute complement set , recorded as a ' or? U (a) or ~a;

Power set

There is set a, which is owned by set a subset A collection of components, called Collection A. Power Set ;


The following are common operations related to the python3.6.3 version collection, and by the way, take notes down

Import sys,osprint (sys.version)   #3 .6.3  (v3.6.3:2c5fed8, oct  3 2017,  18:11:49)  [MSC v.1900 64 bit  (AMD64)]s = set ([1,3,5,8,4])   #创建一个数值集合t  = set ("Hello")   #创建一个唯一字符的集合a  = t | s # t  and  s  set B Intersection of  = t & s # t  and  s  c = t - s #   difference set (in T, but not in s) d = t ^ s #  symmetric difference set (in T or S, but not both) # #basic  operationt.add ( ' x ')   #addings. Update ([100,200,300])   #在s中添加多项t. Remove (' H ')   #删除一项len (s)   #集合长度 ' x '  in  s  #测试x是不是s的成员 ' x '  not in s  #测试xs. Issubset (t)   #s中的每个元素都在t中s  <=  Ts.issubset (t)   #t中的每个元素都在s中s  >= ts.union (t)  #  returns a new set that contains each element in S and T s |  Ts.intersection (t)   #返回一个新的set, contains the common elements in S and T s & ts.difference (t)   #返回一个新的set, Contains elements that are in s but not in T s - ts.symmEtric_difference (t)   #返回一个新的set, contains non-repeating elements in S and T S ^ ts.copy ()   A shallow copy of the #返回set  s 




python3.6 Collection Notes (i)

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.