Answer to Question #322809 in Python for Pravallika

Question #322809

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




Input




The first line of input String A.



The second line of input 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.




1
Expert's answer
2022-04-03T18:31:30-0400

Use the following set of codes:

# A program to remove all words with k length from a string
string = input("Please enter a string: ")
k = int(input("Enter integer k: "))
result = string.split()
list_0 = []
while result:
    current = result.pop()
    if len(current) != k:
        list_0.append(current)
new_list = reversed(list_0)
string = ' '.join([str(item) for item in new_list])
print(string)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS