The check list changes and deletions sorting

'' ' 
Deletions check and change the ordering #list 
# increase list 
List = [ "Hello", "Linda", 13 is, "available for purchase", "to", "China"] 

#list increase 
a = list.append ( "Chichy") # increase string 
print (list) 
B = list.append (123) # increasing digital 
print (list) 
C = list.append ([1,2,3,4]) # Add list 
print (list ) 
D = list.append ((. 1, "Hi",. 8)) # increase tuple 
print (List) 
E = list.append ({. 1: "One", 2: "TWO"}) # increase dictionary 
print ( list) 


# inserted list 
list = [ "Hello", "Linda", 13 is, "available for purchase", "to", "China"] 
a = list.insert (56 is, "Hi") # behind the content to be inserted in write index, and then write the content to be inserted in the back 
Print (List) 
B = list.insert (. 1, {1,2,3})
print(list)


list=["hello","Linda",13,"welcome"] 
C = list.extend ( "China") # string will disassembled into a string of characters consisting of
print(list)#['hello', 'Linda', 13, 'welcome', 'C', 'h', 'i', 'n', 'a']


Print (List) [ 'Hello', 13 is] 
# remove list puncturing element according to delete 
List = [ "Hello", "Linda", 13 is, "available for purchase"] 
A list.remove = ( "Hello") # deleted character string hello, if they are deleted string is not in the list. Will be wrong





Print (List) 



# del delete list can be deleted according to the index, can also be used to delete sections'is available for purchase'] 
List [0: 2] = "Good" # If you need to two elements, you only gave one, then dismantling will be the first element of Chengdu, a single-character string 
List = [ "Hello", "Linda", 13 is, "available for purchase"] 
del List [-1]
Print (List) 
del List [2:] 
Print (List) 
del List [0:] 
Print (List) 
#resultThe 
# [ 'Hello', 'Linda', 13 is] 
# [ 'Hello', 'Linda'] 
# [ ] 



# clear clear clear not required argument list 
list = [ "hello", "Linda", 13 is, "available for purchase"] 
a = list.clear () 
Print (list) # [] 



# list search 
list = [ "hello "," Linda ", 13 is," available for purchase "] 
Print (list [0:]) # view the elements of a list 
for I in list: 
    Print (I) 



modified # list 
list = [" hello "," Linda ", 13 is, "available for purchase"] 
List [0] = "the Hello" 
Print (List) # [ 'the Hello', 'Linda', 13 is, 'available for purchase'] 
Print (List) # [ 'G', 'o', 'o', 'd', 13, 'welcome']

list=["hello","Linda",13,"welcome"]
list[0:2]="GOOD","smart"
Print (List) # [ 'GOOD', 'Smart', 13 is, 'available for purchase'] 

##### only index list, the string for the find and index, find the index of the element back to looking for, there is no 
### find returns -1, while the index can not find on the error. 




# Sorted list 
#sort table inside the small number of cases sorted in increasing order 
A = [1,4,2,6,3,5] 
# A1 = a.sort (Reverse = False) and # a.sort () equivalent 
A1 = a.sort () # [. 1, 2,. 3,. 4,. 5,. 6] 
Print (a) 

#sort (Reverse = True) the list of numbers inside the descending order 
a2 = a. Sort (Reverse = True) 
Print (a) # [. 6,. 5,. 4,. 3, 2,. 1] 

#reverse () to restore a list of numbers inside ordered into a sequence beginning 
A3 = a.reverse () 
Print (a ) # [1, 2, 3, 4, 5, 6]

 

Guess you like

Origin www.cnblogs.com/GZ1215-228513-Chichy/p/11286044.html