python使用sorted函数对列表进行排序的方法
本文实例讲述了python使用sorted函数对列表进行排序的方法。分享给大家供大家参考。具体如下:
python提供了sorted函数用于对列表进行排序,并且可以按照正序或者倒序进行排列
#创建一个数字组成的列表 numbers = [5, 1, 4, 3, 2, 6, 7, 9] #输出排序后的数字数组 print sorted(numbers) #输出原始数组,并未被改变 print numbers my_string = ['aa', 'BB', 'zz', 'CC', 'dd', "EE"] #按字符顺序对字符串列表进行排序,默认为按字符顺序排序 print sorted(my_string) #使用reverse=True按照首字符的倒序进行排序 print sorted(strs, reverse=True) ## ['zz', 'aa', 'CC', 'BB']
希望本文所述对大家的Python程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Many website developers face the problem of integrating Node.js or Python services under the LAMP architecture: the existing LAMP (Linux Apache MySQL PHP) architecture website needs...

When using Scapy crawler, the reason why pipeline persistent storage files cannot be written? Discussion When learning to use Scapy crawler for data crawler, you often encounter a...

Choice of Python Cross-platform desktop application development library Many Python developers want to develop desktop applications that can run on both Windows and Linux systems...

Python process pool handles concurrent TCP requests that cause client to get stuck. When using Python for network programming, it is crucial to efficiently handle concurrent TCP requests. ...

Deeply explore the viewing method of Python functools.partial object in functools.partial using Python...

Getting started with Python: Hourglass Graphic Drawing and Input Verification This article will solve the variable definition problem encountered by a Python novice in the hourglass Graphic Drawing Program. Code...

How to handle high resolution images in Python to find white areas? Processing a high-resolution picture of 9000x7000 pixels, how to accurately find two of the picture...

Data Conversion and Statistics: Efficient Processing of Large Data Sets This article will introduce in detail how to convert a data list containing product information to another containing...
