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 | Program to Create two lists with EVEN numbers and ODD numbers from a list



Here, we will learn how to create two lists with EVEN and ODD numbers from a given list in Python? To implement this program, we will check EVEN and ODD numbers and appends two them separate lists.
Submitted by IncludeHelp, on July 26, 2018

Given a list, and we have to create two lists 1) list with EVEN numbers and 2) list with ODD numbers from given list in Python.

Example:

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

    Output:
    List with EVEN numbers: [22, 44]
    List with ODD NUMBERS: [11, 33, 55]

Logic:

To create lists with EVEN and ODD numbers, we will traverse each element of list1 and append EVEN and ODD numbers in two lists by checking the conditions for EVEN and ODD.

Program:

# declare and assign list1
list1 = [11, 22, 33, 44, 55]

# declare listOdd - to store odd numbers
# declare listEven - to store even numbers
listOdd = []
listEven = []

# check and append odd numbers in listOdd
# and even numbers in listEven
for num in list1:
	if num%2 == 0:
		listEven.append(num)
	else:
		listOdd.append(num) 

# print lists
print "list1:    ", list1 
print "listEven: ", listEven
print "listOdd:  ", listOdd

Output

    list1:     [11, 22, 33, 44, 55]
    listEven:  [22, 44]
    listOdd:   [11, 33, 55]





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.