Python program to print even length words in a string
Given a string. The task is to print all words with even length in the given string.
Input: s = "This is a python language" Output: This is python language Input: s = "i am laxmi" Output: am
Method: Finding even length words using for loop and if statement and without using the def function. First split the given string using the split() function and then iterate the words of a string using for loop. Calculate the length of each word using the len() function. If the length is even, then print the word.
This is python language
Approach: Split the string using split() function. Iterate in the words of a string using for loop. Calculate the length of the word using len() function. If the length is even, then print the word. Below is the Python implementation of the above approach:
Method: Using the lambda function
Method: Using list comprehension