Python Learning Notes _ data sorting method

Source: Internet
Author: User
1. Sort in place: Use the sort () method to arrange the data in the order specified and replace the original data with the sorted data (the original order is lost), such as:

Copy the Code code as follows:


>>> data1=[4,2,6,432,78,43,22,896,42,677,12]
>>> Data1.sort ()
>>> data1 #原来的顺序被替换
[2, 4, 6, 12, 22, 42, 43, 78, 432, 677, 896]

2. Copy sort: Using sorted () built-in functions, arrange the data in the order specified to return an ordered copy of the original data (in the original order), such as:

Copy the Code code as follows:


>>> data1=[4,2,6,432,78,43,22,896,42,677,12]
>>> data2=sorted (data1)
>>> data1
[4, 2, 6, 432, 896, 677, A.,] #原顺序保留
>>> data2
[2, 4, 6, A, 432, 677, 896] #对副本排序
>>>
  • 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.