Python (Listing 2)

Source: Internet
Author: User

1.remove (removes the element with the specified value)

x = [' To ', ' is ', ' or ', ' not ', ' to ', ' being ']

X.remove (' Be ')

X

[' to ', ' or ', ' no ', ' to ', ' being ']

2.reverse (the elements in the list are arranged in reverse order)

s = [+/-]

S.reverse ()

S

[3,2,1]

3.sort (in order)

x = [2,3,4,5,7,9,6,0]

X.sort ()

X

[0,2,3,4,5,6,7,9]

Sorted function

x = [4,6,2,1,7,9]

y = sorted (x)

X

[4,6,2,1,7,9]

Y

[1,2,4,6,7,9]

4. Advanced Sort: Method sort accepts two optional parameters: Key and reverse

x = [' Aardfgasgas ', ' Sasasasas ', ' a ', ' AAA ']

X.sort (key = len) sorted by length

X

[' A ', ' aaa ', ' Sasasasas ', ' Aardfgasgas ']

x = [4,6,5,7,2,1]

X.sort (reverse=true) specifies a value of True or false, sorted in reverse order

X

[1,2,4,5,6,7]

Python (Listing 2)

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.