A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a Python program to remove words from a given list of strings containing a character or string
Q:

Write a Python program to remove words from a given list of strings containing a character or string

0

Write a Python program to remove words from a given list of strings containing a character or string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def remove_words(in_list, char_list):
    new_list = []
    for line in in_list:
        new_words = ' '.join([word for word in line.split() if not any([phrase in word for phrase in char_list])])
        new_list.append(new_words)
    return new_list
     
str_list = ['Red color', 'Orange#', 'Green', 'Orange @', "White"]
print("Original list:")
print("list1:",str_list)
char_list = ['#', 'color', '@']
print("\nCharacter list:")
print(char_list)
print("\nNew list:")
print(remove_words(str_list, char_list))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now