Python list operations are always desired to have shorthands as they are used in many places in development. Hence having knowledge of them always remains quite useful.

Let’s deals with finding one such utility of having index of first element greater than K by one-liner. There are various ways in which this can be achieved.

**Method #1 : Using next() + enumerate()**

Using

`next()`

returns the iterator to the element that has been using the `enumerate()`

. We simply put the condition for enumerate and `next()`

picks appropriate element index.
`# Python3 code to demonstrate ` `# to find index of first element just ` `# greater than K ` `# using enumerate() + next() ` ` ` `# initializing list ` `test_list ` `=` `[` `0.4` `, ` `0.5` `, ` `11.2` `, ` `8.4` `, ` `10.4` `] ` ` ` `# printing original list ` `print` `(` `"The original list is : "` `+` `str` `(test_list)) ` ` ` `# using enumerate() + next() to find index of ` `# first element just greater than 0.6 ` `res ` `=` `next` `(x ` `for` `x, val ` `in` `enumerate` `(test_list) ` ` ` `if` `val > ` `0.6` `) ` ` ` `# printing result ` `print` `(` `"The index of element just greater than 0.6 : "` ` ` `+` `str` `(res)) ` |

*chevron_right*

*filter_none*

**Output:**

The original list is : [0.4, 0.5, 11.2, 8.4, 10.4] The index of element just greater than 0.6 : 2

**Method #2 : Using filter() + lambda**

Using filter along with lambda can also help us to achieve this particular task, subscript index value 0 is used to specify that first element greater than value has to be taken.

`# Python3 code to demonstrate ` `# to find index of first element just ` `# greater than K ` `# using filter() + lambda ` ` ` `# initializing list ` `test_list ` `=` `[` `0.4` `, ` `0.5` `, ` `11.2` `, ` `8.4` `, ` `10.4` `] ` ` ` `# printing original list ` `print` `(` `"The original list is : "` `+` `str` `(test_list)) ` ` ` `# using filter() + lambda ` `# to find index of first element just ` `# greater than 0.6 ` `res ` `=` `list` `(` `filter` `(` `lambda` `i: i > ` `0.6` `, test_list))[` `0` `] ` ` ` `# printing result ` `print` `(` `"The index of element just greater than 0.6 : "` ` ` `+` `str` `(test_list.index(res))) ` |

*chevron_right*

*filter_none*

**Output:**

The original list is : [0.4, 0.5, 11.2, 8.4, 10.4] The index of element just greater than 0.6 : 2

**Method #3 : Using map() + index()**

`map()`

along with the `index()`

can also return the desired element index and has the similar internal working as method 1 as discussed above.
`# Python3 code to demonstrate ` `# to find index of first element just ` `# greater than K ` `# using map() + index() ` ` ` `# initializing list ` `test_list ` `=` `[` `0.4` `, ` `0.5` `, ` `11.2` `, ` `8.4` `, ` `10.4` `] ` ` ` `# printing original list ` `print` `(` `"The original list is : "` `+` `str` `(test_list)) ` ` ` `# using map() + index() ` `# to find index of first element just ` `# greater than 0.6 ` `res ` `=` `list` `(` `map` `(` `lambda` `i: i> ` `0.6` `, test_list)).index(` `True` `) ` ` ` `# printing result ` `print` `(` `"The index of element just greater than 0.6 : "` ` ` `+` `str` `(res)) ` |

*chevron_right*

*filter_none*

**Output:**

The original list is : [0.4, 0.5, 11.2, 8.4, 10.4] The index of element just greater than 0.6 : 2

## Recommended Posts:

- Python - Rearrange elements second index greater than first
- Python | Get first index values in tuple of strings
- Minimum value of K such that sum of cubes of first K natural number is greater than equal to N
- Python | Find smallest element greater than K
- Python - Test if greater than preceding element in Tuple List
- Python | Subtract two list elements if element in first list is greater
- Python | Replace elements in second list with index of same element in first list
- Python | Get first element with maximum value in list of tuples
- Python | Get first element of each sublist
- Get row numbers of NumPy array having element larger than X
- Python - Test if common values are greater than K
- Python | Check if all the values in a list that are greater than a given value
- Python | Number of values greater than K in list
- Python | Remove tuples from list of tuples if greater than n
- Python | Indices of numbers greater than K
- Python | Select dictionary with condition given key greater than k
- Python | Records with Key's value greater than K
- Python - Nth smallest Greater than K
- Python - Storing Elements Greater than K as Dictionary
- Python - Filter and Double keys greater than K

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.