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
- Absolute and Relative Imports in Python
- Python | Relative Layout in Kivy
- Python | Relative Layout in Kivy using .kv file
- Count Negative Numbers in a Column-Wise and Row-Wise Sorted Matrix
- Absolute and Relative frequency in Pandas
- Sorted() function in Python
- SymPy | Permutation.order() in Python
- Python | Shuffle two lists with same order
- Python | Check if list is sorted or not
- Python | Combining two sorted lists
- Python sorted containers | An Introduction
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.