Computer Science, asked by anaghadevadas0084, 6 months ago

python program to write a lambda function to remove a specific word from a given list ​

Answers

Answered by poojan
15

Program:

words=[ 'hi', 'hello', 'happy', 'peace', 'hi', 'sad', 'cool', 'depressed', 'chill' , 'sad']

remove_words=[]

n=int(input("Enter the number of words to be removed: "))

for i in range(n):

   remove_words.append(input("Enter the word to be removed: "))

print(list(filter(lambda word: word not in remove_words, words)))

Sample Input:

Enter the number of words to be removed: 2

Enter the word to be removed: sad

Enter the word to be removed: depressed

Output:

['hi', 'hello', 'happy', 'peace', 'hi', 'cool', 'chill']

Learn more:

1. Predict the output of the following python program: num,sum=10,0 for i in range(1,num+2,2): if i % 3 == 0: continue sum = sum + i print(sum)

https://brainly.in/question/35223818

2. def find_max(nums):max_num float("-int") # smaller than all other numbersfor num in nums:if num > max_num:# (Fill in the missing line here)return...

https://brainly.in/question/35049689

Similar questions