Sometimes, while working with Python lists, we can have a problem in which we wish to find the indices for K smallest elements. This task can occur in many domains such as web development and while working with Databases. We might sometimes, require to just find the indices of them. Let’s discuss a certain way to find indices of K smallest elements in list.
sorted() + lambda + list slicing
This task can be performed using the combination of above functions. In this the
sorted(), can be used to get the container in a way which requires to get K smallest elements at front end and then the indices can be computed using list slicing.
The original list is : [5, 6, 10, 4, 7, 1, 19] Indices list of min K elements is : [5, 3, 0]
- Python | Find elements of a list by indices
- Python - Non-None elements indices
- Python - Odd elements indices
- Python - Get Indices of Even Elements from list
- Python - Indices of atmost K elements in list
- Python | Indices of N largest elements in list
- Python | Group elements at same indices in a multi-list
- Python | Find indices with None values in given list
- Python | Ways to find indices of value in list
- Python - Find the Maximum of Similar Indices in two list of Tuples
- Python | Indices of sorted list of list elements
- Python - Smallest integer possible from combination of list elements
- Python | Find smallest element greater than K
- Python program to find smallest number in a list
- Python heapq to find K'th smallest element in a 2D array
- Python | Indices of Kth element value
- Python | Get match indices
- Python | K Value Indices Product
- Python | Indices of numbers greater than K
- Python - Minimum element indices
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.