Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,200,364 members, 7,974,515 topics. Date: Monday, 14 October 2024 at 06:39 AM

How To Sort A List In Python? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How To Sort A List In Python? (271 Views)

Tutorial: Object Oriented Programming Paradigm For Beginners in Python / How To Sort Array In Java With User Defined Method ? / Who Wants To Learn Programming In Python Easily Without Stress? READ THIS (2) (3) (4)

(1) (Reply)

How To Sort A List In Python? by yourblogcoach1(m): 6:59pm On Oct 05, 2022
To sort the list in python, you can use the sort() method. It will return the list in ascending order but you can sort by descending order by passing the reverse flag as a TRUE.

Syntax:
list.sort(reverse=True|False, key=myFunc)

See the tutorial guide here https://yourblogcoach.com/sort-a-list-in-python/
Re: How To Sort A List In Python? by ibiyemi28(m): 7:31pm On Oct 05, 2022
Ok. Nice �

Re: How To Sort A List In Python? by willian10: 7:56pm On Oct 05, 2022
U can also pass the list inside a function called sorted
Example
List_1 = [1,3,5,3,6,7]
Sorted(List_1)

(1) (Reply)

Google Microsoft Amazon Zombifying Africa's Tech Industry Through Brain Drain / If You Want To Become A Frontend Developer, Read This! / Data Analysis Using R Programming

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 4
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.