Sometimes, while working with Python Matrix, we can have data arranged randomly and we can have a requirement in which we need to get the element position in sorted order of Matrix. Let’s discuss a certain way in which this task can be performed.
Method : Using list comprehension +
enumerate() + sort() + lambda
The solution to problem can be achieved using the combination of above functions. In these, we need to first arrange element for index value tuple creation using
enumerate() and list comprehension. Then, we employ sort function to perform custom sort using lambda function.
The original list is : [[1, 3, 1], [4, 6], [7, 8, 10]] Sorted order of Matrix elements : [(0, 0), (0, 2), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1), (2, 2)]
- heapq in Python to print all elements in sorted order from row and column wise sorted matrix
- Python | Finding relative order of elements in list
- Python | Get items in sorted order from given dictionary
- Python | Inserting item in sorted list maintaining order
- Python | Relative Layout in Kivy
- Absolute and Relative Imports in Python
- Python | Relative Layout in Kivy using .kv file
- Python program to Convert a Matrix to Sparse Matrix
- Count Negative Numbers in a Column-Wise and Row-Wise Sorted Matrix
- Absolute and Relative frequency in Pandas
- Sorted() function in Python
- Python | Shuffle two lists with same order
- Higher Order Functions in Python
- Python MySQL - Order By Clause
- SymPy | Permutation.order() in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.