- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# Python Indices of numbers greater than K

In this tutorial, we are going to find the indices of the numbers that are greater than the given number K. Let's see the different ways to find them.

A most common way to solve the problem is using the loops. Let's see the steps to solve the problem.

- Initialize the list and K.
- Iterate over the list using its length.
- If you find any number greater than K, then print the current index.

## Example

# initializing the list and K numbers = [3, 4, 5, 23, 12, 10, 16] K = 10 # iterating over thAe list for i in range(len(numbers)): # checking the number greater than K if numbers[i] > K: # printing the number index print(i, end=' ')

## Output

If you run the above code, then you will get the following result.

3 4 6

Let's solve the problem using **enumerate** function. It gives you a tuple for each iteration that includes the element's index and element.

## Example

# initializing the list and K numbers = [3, 4, 5, 23, 12, 10, 16] K = 10 # finding indexes of the numbers greater than K result = [index for (index, number) in enumerate(numbers) if number > K] # printing the indices print(*result)

## Output

If you run the above code, then you will get the following result.

3 4 6

## Conclusion

If you have any doubts in the tutorial, mention them in the comment section.

- Related Articles
- Python – Average of digit greater than K
- Python – Remove characters greater than K
- Python - Consecutive Ranges of K greater than N
- Python – Filter Tuples Product greater than K
- Python - Number of values greater than K in list
- Find smallest element greater than K in Python
- Python – Remove Tuples with difference greater than K
- Python - Get the Index of first element greater than K
- Python – Extract dictionaries with values sum greater than K
- Python – Extract list with difference in extreme values greater than K
- Python – Find the frequency of numbers greater than each element in a list
- Program to split lists into strictly increasing sublists of size greater than k in Python
- Count of alphabets having ASCII value less than and greater than k in C++
- Write five rational numbers greater than $-2$.
- Largest subarray having sum greater than k in C++

Advertisements