Recently to go back to school to do the completion of the set, ready to do a related algorithm, I heard that Python operations better, specifically to learn.
Let's start with the basics .......... ...........
D3
1.set elements are not duplicated, no order. Can be a tuple type
1 #the way to create a set is to call set () and pass in a list,list element as the set element:2 3>>> s = Set (['A','B','C'])4 5>>>Prints6Set (['A','C','B'])7 8>>> s = Set (['A','B','C','C'])9>>>PrintsTenSet (['A','C','B']) One>>>Len (s) A3
1>>>s = Set ([('Adam', 95), ('Lisa', 85), ('Bart', 59)])2>>> forXinchS:3>>>PrintX[0],':', x[1]4 5 #lisa:856 #adam:957 #bart:59
2. Access set content can be used in. The speed is very fast, the content is immutable and cannot be changed. Facilitates finding specific keywords in ' dictionaries '.
>>> ' Hello ' in s
False
>>> ' A ' in S
True
>>> ' A ' in S
False
Case sensitive, case default is not the same character
The 3.set traversal method can be used for loops
>>> for X in S
>>>>>>print x
A
4.set.add (' element ') adds an element to the set, and Set.remove (' element ') removes the element from the set.
Where an existing element is added, no error is made, and it is not added. Deleting an element that does not exist will cause an error.
Python, I learned from scratch t^t D3