Creation of lists
1, common method to create a list
list = []
2, list analysis, List deduction type
Using list parsing can be almost 1 time times faster than using a normal method. It is therefore recommended to use list parsing.
Grammar
[Expression for Iter_val in iterable if COND_EXPR]
Requirements: List 1~10 of all numbers squared >>>l = [i**2 for i in range (1,11)]>>>print l[1, 4, 9, 16, 25, 36, 49, 64, 8 1, +]
Updates to the list
>>> list = [1,2,3 >>> list.append (" 4 ") # add list item >>> list[ 1, 2, 3, " 4 " >>> del list[3] # delete list item >>> list[ 1, 2, 3]
>>> List1 = [All in all]>>> list2 = [4,5,6]>>> list1.extend (list2)# append multiple values at once >>> list1[1, 2, 3, 4, 5, 6]
>>> list = [1,2,2,3,4]>>> list.remove (2)# Remove the first occurrence of a value in the list >>> list[1, 2, 3, 4]>>> list.pop ()# removes an element from the list (the last element by default) and returns the value of the element 4 >>> list[1, 2, 3]
>>> list = [List.insert]>>> 1,4# insert >>> list[1, 4, 2, 3]
List Common methods
List.index ()
# Find the element location >>> list = [List.index]>>> A (2)1
List.count ()
List.reserve ()
# Invert >>> list = [List.reverse]>>> ()>>> list[ 3, 2, 1]
List.clear ()
# Empty list >>> lists = [list.clear]>>> ()>>> list[]
List.sort ()
>>> list = [1,3,2,6,5]>>> list.sort ()# sorting >>> list[1 , 2, 3, 5, 6]
python--List