Here, we are going to actualize a python program that will print the list in the wake of expelling ODD numbers.
Given a list, and we need to print the list in the wake of expelling the ODD numbers in Python.
Input: list = [11, 22, 33, 44, 55] Output: list after removing ODD numbers list = [22, 44]
- Navigate each number in the list by utilizing for…in circle.
- Check the condition for example checks number is separable by 2 or not – to check ODD, the number must not be distinguishable by 2.
- On the off chance that number isn’t distinct by 2 for example ODD number from the list, use list.remove() strategy.
# list with EVEN and ODD number list = [11, 22, 33, 44, 55] # print original list print "Original list:" print list # loop to traverse each element in the list # and, remove elements # which are ODD (not divisible by 2) for i in list: if(i%2 != 0): list.remove(i) # print list after removing ODD elements print "list after removing ODD numbers:" print list
Original list: [11, 22, 33, 44, 55] list after removing ODD numbers: [22, 44]