A summary of the review of the second day course
1, the list can be deleted and changed, the tuple is not modifiable list, the string is not modifiable.
2, the list, the tuple is ordered, the dictionary is unordered, the dictionary key is unique
3. List dictionary can be nested list, can nest dictionary, can nest multi-layer
4, the dictionary does not need to save the subscript, is to find the value by key (value)
Two, set
1, set characteristics: disorder, non-repetition, relationship testing
2. Relationship Testing
A, intersection: Remove the repeating part between the two sets a.intersection.b
b, the assembly: two aggregate element sum, (including repeating part, repetition is unique) a.union.b
C, the difference set: B A in there is no, there is no a.difference.b in a b-a,b b.difference.a
D, subset, parent set: A contains a subset of B,b, and A is the parent set of B b.issubset.a the parent collection a.issuperset.b
F, Symmetric difference set: Take two sets of the sum, remove the repetition of the part. A.symmetric_difference. B
G, Isdisjoint returns True if there is no intersection
1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 #@Author: Willpower-chen4 #@blog: http://www.cnblogs.com/willpower-chen/5List_1 = Set ([1,3,5,7,9,0,10])6List_2 = Set ([2,4,6,8,0,10])7List_3 = Set ([1,3,5])8List_4 = Set ([2,4,6])9 Ten Print('intersection'. Center (50,'-')) One Print('list_1.intersection (list_2)') A Print(List_1.intersection (list_2)) - Print('Another way of writing') - Print('List_1 & List_2') the Print(List_1 &list_2) - - Print('and set'. Center (50,'-')) - Print('list_1.union (list_2)') + Print(List_1.union (list_2)) - Print('Another way of writing') + Print('list_1 | list_2') A Print(List_1 |list_2) at - Print('Difference Set'. Center (50,'-')) - Print('list_1.difference (list_2)') - Print(List_1.difference (list_2)) - Print('list_2.difference (list_1)') - Print(List_2.difference (list_1)) in Print('Another way of writing') - Print('list_1-list_2') to Print(List_1-list_2) + Print('list_2-list_1') - Print(List_2-list_1) the * Print('determining subsets, Parent set relationships'. Center (50,'-')) $ Print('List_3.issubset (list_1)')Panax Notoginseng Print(List_3.issubset (list_1)) - Print('List_1.issuperset (list_3)') the Print(List_1.issuperset (list_3)) + A the + Print('Symmetric difference Sets'. Center (50,'-')) - Print('list_1.symmetric_difference (list_2)') $ Print(List_1.symmetric_difference (list_2)) $ Print('Another way of writing') - Print('list_1 ^ list_2') - Print(list_1 ^list_2) the - Print('To determine whether there is a overlap'. Center (50,'-'))Wuyi Print('have intersection return false') the Print('list_1.isdisjoint (list_2)') - Print(List_1.isdisjoint (list_2)) Wu Print('no intersection returns True') - Print('list_3.isdisjoint (list_4)') About Print(List_3.isdisjoint (List_4))Source Code
list_1 {0, 1, 3, 5, 7, 9, 10}list_2 {0,2, 4, 6, 8, 10}list_3 {1, 3, 5}list_4 {2, 4, 6}------------------------intersection------------------------list_1.intersection (list_2) {0,10} Another way to List_1&list_2{0,10}------------------------and set------------------------list_1.union (list_2) {0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Another way to List_1|list_2{0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10}------------------------Difference Set------------------------list_1.difference (list_2) {1, 3, 5, 9, 7}list_2.difference (list_1) {8, 2, 4, 6} Another way to List_1-list_2{1, 3, 5, 9, 7}list_2-list_1{8, 2, 4, 6}--------------------the subset of the judgment, the parent set relationship---------------------List_3.issubset (list_1) truelist_1.issuperset (list_3) True-----------------------Symmetric difference Set-----------------------list_1.symmetric_difference (list_2) {1, 2, 3, 4, 5, 6, 7, 8, 9} Another way to List_1^list_2{1, 2, 3, 4, 5, 6, 7, 8, 9}----------------------to judge whether there is a overlap----------------------there is a intersection return Falselist_1.isdisjoint (list_2) False without intersection returns TRUELIST_3.ISDISJOINT (list_4) TrueResults
3. Set other operations
A, increase: add,update; add can only add a single element, update adds one or more collections
B, Delete: remove specifies that the element is deleted (only one can be deleted) and the deletion does not exist in the collection will be an error,
Discard Delete does not exist in the collection does not error,
Pop randomly deletes one and returns the deleted element
C, in, or not in: Determines whether a dictionary, or a list, can be judged in a set.
set_1 {1, 3, 5, 7, 9, 10}set_2 {8, 2, 10, 4, 6}set_3 {'a', 1, 3, 5}set_4 {2, 4,'b', 6}------------------------Increase-------------------------Set_1.add (88) set_1 {1, 3, 5, 7, 9, 10, 88}set_1.update (set_2,set_3) set_1 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,'a', 88}------------------------Delete------------------------Set_1.pop () set_1 {2, 3, 4, 5, 6, 7, 8, 9, 10,'a', 88the value of the}pop_value1Set_1.remove (10) set_1 {2, 3, 4, 5, 6, 7, 8, 9,'a', 88}set_1.discard (7) set_1 {2, 3, 4, 5, 6, 8, 9,'a', 88}View Code
Third, file operation
1, in order to operate the file, you must assign an object to the memory of the open file
f = open (file, ' R ', enconding= ' utf-8 ')
F.close ()
F is file handle: Memory object, file size and other attributes
2, R read only; W write only create a new file, the original file will be overwritten; a i.e. append, append unreadable
3, F.readline () read a line, F.readlines () to save the file contents to memory at once, so only for small files
4, F.tell () print the current position; F.seek () The position of the pointer; F.enconding ()
The third day of the Python devops development