Advertisements
Advertisements
Question
Write a short note about sort( ).
Advertisements
Solution
Function : Sort ()
Syntax:
List.sort( reverse=True | False, key=my Func)
- Both arguments are optional.
- If the reverse is set as True, list sorting is in descending order.
- Ascending is the default.
Description:
Sort () function sorts the elements in the list
Example:
MyList=[‘Thilothamma’, ‘Tharani’, ‘Anitha’, ‘SaiSree’, ‘Lavanya’]
MyList.sort()
print(MyList)
MyList.sort(reverse=True)
print(MyList)
Output:
[‘Anitha’, ‘Lavanya’, ‘SaiSree’, ‘Tharani’, ‘Thilothamma’]
[‘Thilothamma’, ‘Tharani’, ‘SaiSree’, ‘Lavanya’, ‘Anitha’]APPEARS IN
RELATED QUESTIONS
Let list1 = [2,4,6,8,10], then print(List1[-2]) will result in ______
Which of the following function is used to count the number of elements in a list?
Which of the following Python function can be used to add more than one element within an existing list?
Which of the following statement is not correct?
The keys in Python, the dictionary is specified by ______
What is a List in Python?
Differentiate del with remove( ) function of List.
What will be the output of the following code?
list = [2**x for x in range(5)]
print(list)
What is the difference between List and Dictionary?
What is the purpose of range( )? Explain with an example.
