#List[Ordered variable sequence]
DefLists ():
# ---List---
#List is available byAppend ()/pop ()Method,Use as a stack
#List is available byDeque ()Packaging,Use as a two-way queue
#Create
Lists = [A,"B","C"]#List
Lists =List ()#Empty list
Lists =List (1,2,3))# (To convert a tuple to a list(Note:Converting a dictionary to a list can lose data)
Lists = [IFor IInchRange10)]#Other: [(10,i) for I in range (10)]
#Statistics
Length =Len (lists)#List length
Count = Lists.count ("C")#Count the number of elements
#Get
STR0 = lists[0]#Take out the data in the list
Lists = lists[0:3]
Lists = lists[0:3:2]
Ary2 = Lists.copy ()#Shallow Copy List
#Find
Lists = [A,"B",C,' B ',A,C,' d ',' B ',A,' B ']#List
index = Lists.index ("B")#Query the location of the element,There is no throwing exception(Attention) = 1
index = Lists.index ("B",2)#Start position, default is0 =>3
index = Lists.index ("B",4,8)#End position, default is list length=>7
Elem =Min (lists)
Elem =max (lists)
# traverse
for i in lists:
Span style= "COLOR: #8888c6" >print ( "for:%s"% i)
# modify
Lists[0] = "0" # Modify the first Data
Lists.reverse () # reverse
Lists.sort () # ( natural order ) sort
#Add to
Lists.append ("D")#Add data(Add to End)
Lists.insert (1,"A1")#Inserting data
Lists.extend (["D",E, "F"]) # Add Data ( element appended to end )
Lists = [1, 2] + [3, 4] # Merge list
Lists = [1, 2] * 3 # add element to itself 3 times
#Delete
Del lists[1]#Delete based on index(Attention)
Lists.pop ()#Delete last Element
Lists.remove (1)#Delete based on element,Throw a line if you can't find it
Lists.clear ()#Clear List
#Judge
Boolean = "a" in lists # Whether the element exists in the list
boolean = " a "not in lists # If the element does not exist in the list
# sort
lists = sorted (lists) # dictionary ( unordered variable map type , key-value pair collection , and key unique )
python3-note-b-001-data structure-list list[]