Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » Python programs

Python | print list after removing ODD numbers



Here, we are going to implement a python program that will print the list after removing ODD numbers.
Submitted by IncludeHelp, on August 06, 2018

Given a list, and we have to print the list after removing the ODD numbers in Python.

Example:

    Input:
    list = [11, 22, 33, 44, 55]

    Output:
    list after removing ODD numbers
    list = [22, 44]

Logic:

  • Traverse each number in the list by using for...in loop.
  • Check the condition i.e. checks number is divisible by 2 or not – to check ODD, number must not be divisible by 2.
  • If number is not divisible by 2 i.e. ODD number from the list, use list.remove() method.

Program:

# 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

Output

    Original list:
    [11, 22, 33, 44, 55]
    list after removing ODD numbers:
    [22, 44]





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.