1.

Write a short note about sort( )?

Answer»

sort( ) function sorts the element in list.

Syntax:

List.sort (reverse = True/False, Key = myFunc) Both arguments are optional

  • If reverse is set as True, list sorting is in descending order.
  • Ascending is default.
  • Key=myFunc; “myFunc” – the name of the user defined function that specifies the sorting criteria.

Example

My List=[‘Thilothamma’ , ’Tharani’ , ‘Anitha’ , ‘SaiSree’ ,

‘Lavanya’]

MyList.sort( )

print(MyList)

Output:

[‘Anitha’ , ‘Lavanya’ , ‘SaiSree’ , ‘Tharani’ , ‘Thilothamma’]



Discussion

No Comment Found