Se7enSquared
10/18/2019 - 12:41 AM

Strip bad characters out of a list of strings

Given a list of 'bad characters', iterate through that list and clean the data, removing said characters

test_data = ["1912", "1929", "1913-1923",
             "(1951)", "1994", "1934",
             "c. 1915", "1995", "c. 1912",
             "(1988)", "2002", "1957-1959",
             "c. 1955.", "c. 1970's", 
             "C. 1990-1999"]

bad_chars = ["(",")","c","C",".","s","'", " "]

def strip_characters(string):
    for char in bad_chars:
        string = string.replace(char,"")
    return string


stripped_test_data = []

for item in test_data:
    stripped_test_data.append(strip_characters(item))