< Tanzhou Education >-python Learning notes @ Job 2

Source: Internet
Author: User
Tags shallow copy

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.