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.


    str: Python is a programming language

    EVEN length words:


  • 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.


# 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


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

Python String Programs »

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

© some rights reserved.