Sometimes, while working with lists, we can have a problem in which we need to extract certain numbers occurring first time. This can also be even number. This kind of problem is common in day-day and competitive programming. Lets discuss certain ways in which this task can be performed.
Method #1 : Using loop
This is brute force way in which this task can be performed. In this, we loop through the list and when 1st time even number occurs, we store and break the loop.
The original list is : [43, 9, 6, 72, 8, 11] The first even element in list is : 6
Method #2 : Using binary search (Sorted list)
The binary search can also be employed on list when we have sorted list. In this, we keep looking for smaller even term when we find one and move to rear end in case we don’t find one.
The original list is : [3, 7, 8, 9, 10, 15] The first even element in list is : 8
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python Number | cmp(list) method
- Python | Sum of number digits in List
- Python | Largest number possible from list of given numbers
- Python | Number of values greater than K in list
- Python | Assign value to unique number in list
- Python | Find closest number to k in given list
- Python | Convert number to list of integers
- Generating random number list in Python
- Python - Generate random number except K in list
- Python | Generate random number except K in list
- Python | Count number of items in a dictionary value that is a list
- Python - Match Kth number digit in list elements
- Python program to find largest number in a list
- Python program to find second largest number in a list
- Python program to find smallest number in a list
- Python | Replace list elements with its ordinal number
- Python program to find number of m contiguous elements of a List with a given sum
- Python | Convert list of tuples to list of list
- Python | Convert list of string to list of list
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.