Q:

How to delete/ignore an entire line in a string if there is a certain character in that line using Python?

If a multi-line string contains a certain character like '$', how can I erase/ignore the whole line that character reside?
Note: The task is to get rid of any lines containing a certain character and not empty lines. 
testString = """unknown value 1
                unknown value 2
                unknown value 3
                $ unknown value 4
                unknown value 5"""

A:

First, you can split the string into a list of lines using the splitlines function. Then, using list comprehension you can iterate through the lines and test each line for the presence of "$", and return a new list of lines without any lines containing "$". Then you would recombine the new list with "\n" (the newline character) back into a string.
Here is the code:
testString = """unknown value 1
                unknown value 2
                unknown value 3
                $ unknown value 4
                unknown value 5"""

newTestString = "\n".join([x.strip() for x in testString.splitlines() if "$" not in x])

