- Related Questions & Answers
- Python - Number of values greater than K in list
- Find smallest element greater than K in Python
- Python - Get the Index of first element greater than K
- Count of alphabets having ASCII value less than and greater than k in C++
- Program to split lists into strictly increasing sublists of size greater than k in Python
- Count of subarrays whose maximum element is greater than k in C++
- Count subarrays with all elements greater than K in C++
- Count the number of words having sum of ASCII values less than and greater than k in C++
- Find Smallest Letter Greater Than Target in Python
- Getting equal or greater than number from the list of numbers in JavaScript
- Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold in C++
- Two Sum Less Than K in Python
- Adding elements of an array until every element becomes greater than or equal to k in C++.
- Program to find lowest sum of pairs greater than given target in Python
- Count natural numbers whose all permutation are greater than that number in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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.

# 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=' ')

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.

# 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)

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

3 4 6

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

Advertisements