135k views
4 votes
g Given a character and a list of strings, find strings that do not contain the given character. See the example below. $ (Find 88 (list (list 77 73) (list 89))) ((77 73) (89)) $ (Find 88 (list (list 7

User Srinivasu
by
3.6k points

1 Answer

2 votes

Answer:

The solution code is written in Python 3

  1. def findStr(stringList, c):
  2. output = []
  3. for currentStr in stringList:
  4. if c not in currentStr.lower():
  5. output.append(currentStr)
  6. return output
  7. strList = ["Apple", "Banana", "Grape", "Orange", "Watermelon"]
  8. print(findStr(strList, "g"))

Step-by-step explanation:

Firstly, we can create a function and name it as findStr which takes two input parameters stringList and a character, c (Line 1).

Create a list that will hold the list of strings that do not contain the input character (Line 2).

Create a for-loop to traverse through each string in the list (Line 3).

In the loop, check if the input character is not found in the current string (Line 4), if so, add the current string to the output list (Line 5). Please note we also need to convert the current string to lowercase as this program should ignore the casing.

After completion the loop, return the output list (Line 7).

We can test the function using a sample string list and input character "g" (Line 9 - 10). We shall get the output as follows:

['Apple', 'Banana', 'Watermelon']

User Floyd Wilburn
by
4.5k points