Given a string, write a program to remove all the words with K length
def toString(sen):
s1 = ""
for e in sen:
s1 += e
return s1
def remove(sen, n):
n_w = []
ws = sentence.split(" ")
for w in ws:
if not len(w) == n:
n_w.append(w)
n_w.append(" ")
return toString(n_w)
a = str(input("Enter a sentence:"))
n = int(input("Enter lenth to remove):"))
print(remove(a, n))
Comments
Leave a comment