What is wrong tuple in DBMS

Sometimes, while working with data, we can have a problem of sorting them. There are many types of basis on which sorting can be performed. But this article discusses sorting on the basis of difference of both elements of pair. Let's discuss certain ways in which this can be done.

Method # 1: Using + lambda
The combination of above functionalities can be used to solve this problem. In this, sorting is performed by and lambda function is fed as key to perform desired sorting.

Output: The original list: [(1, 4), (6, 5), (8, 10)] List after sorting by difference: [(6, 5), (8, 10), (1, 4)]

 

Method # 2: Using
This is yet another way to perform this task. In this, we pass the, a comparator function which performs the similar difference logic using. Works only in Python2.



Output: The original list: [(1, 4), (6, 5), (8, 10)] List after sorting by difference: [(6, 5), (8, 10), (1, 4)]

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your data structures concepts with the Python DS Course. And to begin with your machine learning journey, join the Machine Learning - Basic Level Course

My Personal Notesarrow_drop_up