List method:
1LST = ['a','b','C','D']2 ##加3Lst.append ('e')## #增加元素4Lst.extend (['F','g'])## # Expansion List5Lst.insert (1,'e')## Insert Element6 ##减7Lst.remove ('b')## Delete element, return value is None, if no element, error8Lst.pop ()## Remove an element by default,9Lst.pop (1)## #加入索引值, delete the element below the index, return the delete valueTenLst.clear ()##清除掉list One A ##计数, find -Lst.count ('a')## #列表中元素的出现的次数 -Lst.index ('a')## # View the index value of an element in a list the - ##其他 - #l.copy () List--a shallow copy of L -Lst.copy ()## Returns a copy of the list +Lst.reverse ()## Reverse List -Lst.sort ()## # Sort list
# The second time homework
1. use 3 methods to insert values into the list
1 LST = [' A ', ' B ', ' C ', ' d '] 2 # #加 3 lst.append (' E ') # # #增加元素 4 lst.extend ([' F ', ' G ']) # # # Expansion List 5 Lst.insert (1, ' E ') # # inserting elements
#2. in 2 ways , the list li2 =[' A ', ' B ', ' C ', replaced by [' A ', ' Jianeng ', ' C '] .
Method 1: Assign a value to an element
Method 2: Remove the B-value first, and then insert the new value
#3. put the string s = ' Hello python! ', first replace ' python ' with ' 2018 ', then convert to list li=[' Hello ', ' 2018 ', '! ']
#4. the list li4 = [' A ', ' BBB ', ' cc ', ' dddd '], sorted by string length, from large to small. [' dddd ', ' BBB ', ' cc ', ' a ']
# # L.sort (Key=none, Reverse=false), None--stable sort *in place*
#1
Li4 = [' A ', ' BBB ', ' cc ', ' dddd ']li4.sort (key = Lambda X:len (x), reverse=true) print (LI4)
#2
Li4 = [' A ', ' BBB ', ' cc ', ' dddd ']li4.sort (key = Len,reverse = True) print (LI4)
< Tanzhou Education >-python Learning notes @ Job 2