Python for simple sorting

Source: Internet
Author: User

Today I have a magic algorithm, according to the editor is an easy and intresting book, so I began to open.

The author uses the C language, and I am recently eating python so I'm thinking of using Python to solve the author's questions.

This is not, the first page is coming, this is a very simple for the human brain, but for the academic knowledge of the full return to the teacher's people still think of long time, looked for a good while the information.

After thinking, I chose the array, and then search the Python knowledge of the array, the result, it seems that Python does not pay much attention to the array, or not the same, later looked at list and dict, think should be similar, after reference, also came out, really super simple, than the original ecological language implementation of a lot of simple

#!/usr/bin/python#-*-encoding=utf-8-*-a=[1]*5for i in Range (0,5):    a[i]=input () a.sort (reverse=true) print a

Operation Result:

Input: 961027 Get results: [10, 9, 7, 6, 2]

is not very simple, only 5 lines of code, and are the most simple code, small white can also see it.

Summarize:

① Knowledge Points: The basic application of the sort function

This is a list of the sort method, the use is very simple, in the help document directly to see can understand, so lazy I directly stickers

The above shows are the positive sequence arrangement, that is, from small to large arrangement, but the topic requirements from large to small arrangement, so finally still rely on the Universal Blog Park, only to be resolved.

There's nothing to do in the blog Park or (゜▽^*))

②: The program really is to achieve the basic function, but the operation is very cumbersome, input data when I have to enter one, and finally must press ENTER to come out results, I want to see the author is how to solve, and then try to improve their own program!

Welcome to Exchange

(*^__^*) To work time to write blog, I This is enough boring, in order to brush my existence, I go back to work, I hope that small white and the great God can see, and then we exchange discussions together, walk in the program of the road!

Python for simple sorting

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.