Python Sorting Lists — list.sort() vs sorted(list). The 2 common ways to sort a list in Python are inputList.sort() or sorted(inputList). Well, inputList.sort()sorts the list in place, in other words, you loose the original list because it will be mutated to contain the new sorted list.
The 2 common ways to sort a list in Python are inputList.sort()
or sorted(inputList)
.
Well, inputList.sort()
sorts the list in place, in other words, you loose the original list because it will be mutated to contain the new sorted list.
sorted(inputList)
on the other hand returns a new copy of the list in sorted order.
Another important difference is that inputList.sort()
returns None
whereas sorted(inputList)
returns a new list object.
Python list sort() function sorts the list ascending by default. The sort() method sorts the items of a given list in the specific order.
Guide to Python Programming Language
Lists in Python explains what exactly is Lists with an example. Python Lists Tutorial | Lists in Python | Python Programming
Python is an interpreted, high-level, powerful general-purpose programming language. You may ask, Python’s a snake right? and Why is this programming language named after it?
You'll learn how to sort Palindrome Words in a Sentence with Python progam