What is the output of the following? print(sorted([3,1,4,1,5], key=lambda x: -x))

Python Developer Medium

Python Developer — Medium

What is the output of the following? print(sorted([3,1,4,1,5], key=lambda x: -x))

Key points

  • The lambda function reverses the order of elements
  • sorted() sorts the list based on the lambda function
  • The negative sign in the lambda function affects the sorting order

Ready to go further?

Related questions