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 EVEN length words



Here, we are going to implement a Python program, in which we will declare and string and print only EVEN length words.
Submitted by IncludeHelp, on August 01, 2018

Given a string, and we have to print the EVEN length words in Python.

Example:

    Input:
    str: Python is a programming language

    Output: 
    EVEN length words:
    Python 
    is
    language

Logic:

  • To print the EVEN length words, we have to check length of each word.
  • For that, first of all, we have to extract the words from the string and assigning them in a list.
  • Iterate the list using loop.
  • Count the length of each word, and check whether length is EVEN (divisible by 2) or not.
  • If word's length is EVEN, print the word.

Program:

# print EVEN length words of a string 

# declare, assign string
str = "Python is a programming language"

# extract words in list
words = list(str.split(' '))

# print string
print "str: ", str

# print list converted string i.e. list of words
print "list converted string: ", words

# iterate words, get length
# if length is EVEN print word
print "EVEN length words:"
for W in words:
	if(len(W)%2==0 ):
		print W

Output

    str:  Python is a programming language
    list converted string:  ['Python', 'is', 'a', 'programming', 'language']
    EVEN length words:
    Python
    is
    language





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.