Q:

Write a Python program to check if a substring presents in a given list of string values

0

Write a Python program to check if a substring presents in a given list of string values.

All Answers

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

def find_substring(str1, sub_str):
   if any(sub_str in s for s in str1):
       return True
   return False

colors = ["red", "black", "white", "green", "orange"]
print("Original list:")
print(colors)
sub_str = "ack"
print("Substring to search:")
print(sub_str)
print("Check if a substring presents in the said list of string values:")
print(find_substring(colors, sub_str))
sub_str = "abc"
print("Substring to search:")
print(sub_str)
print("Check if a substring presents in the said list of string values:")
print(find_substring(colors, sub_str))

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