Python Numeric sorting exercises

Source: Internet
Author: User

The topic is very simple, request:

2 9 5 7, 6 1 4 8 3 5 4 2 to find the maximum value of each line

Recently just learning python, feel that py can also be done.

#!/usr/bin/env python    
#-*-condig:utf-8-*-    
        
alist = [2,9,5,7]    
print sorted (alist,reverse=true) [0]    
        
Blist = [6,1,4,8]    
print sorted (blist,reverse=true) [0]    
        
clist = [3,5,4,2]    
print sorted (clist,reverse=true) [0]

Thought: First put the need to compare the number in the list, and then use the function sorted to sort, and finally use the index operator [0] to remove the first after the sort, and then print out.

A friend asked, if you want to compare the number of these three lines, there are 100 lines, do you want to manually write 100 lines?

My idea is to consider how to do this 100 lines of content, and the list match up, follow-up demand we are further discussion.

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.