Python Program to Remove all the Words with K Length

 

Remove Words

Given a string, write a program to remove all the words with K length.

Input

The first line of the input will contain a string A.
The second line of the input will contain an integer K.

Output

The output should contain a string after removing all the words whose length is equal to K.

Explanation

For example, string A is “Tea is good for you”, k is 3 then output should be “is good.”

Here words “Tea”, “for”, “you” length is equal to 3, so these words are removed from string.

Sample Input 1
Tea is good for you
3

Sample Output 1
is good

Code:

a=input().split()
k=int(input())
remaining_words_list=[]
for i in a:
    if len(i)!=k:
        remaining_words_list+=[i]
        print(i,end=" ")

Input
A gang stood in front of me
2

Output
A gang stood front

Comments

Popular posts from this blog

CODING ASSIGNMENT 4

CODING PRACTICE 11 Music Page

CCBP Static Website Coding Assignment 2 Solution | Yoga Page