LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

List error in code

https://app.dataquest.io/m/351/cleaning-and-preparing-data-in-python/7/parsing-numbers-from-complex-strings-part-one

I got this error in my code

“stripped_test_data isn’t defined in your code, but we expected it to be list type”

But when I checked the type of “stripped_test_data” , it shows list type and I also got the expected output but then also it is showing error.

I’m not getting what’s wrong in this code

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 d in test_data:
    date = strip_characters(d)
    
    stripped_test_data.append(date)
    
print(type(stripped_test_data))
print(stripped_test_data)


What was expected

stripped_test_data ()

  • actual + expected

  • [undefined]

  • [‘1912’,
  • ‘1929’,
  • ‘1913-1923’,
  • ‘1951’,
  • ‘1994’,
  • ‘1934’,
  • ‘1915’,
  • ‘1995’,
  • ‘1912’,
  • ‘1988’,
  • ‘2002’,
  • ‘1957-1959’,
  • ‘1955’,
  • ‘1970’,
  • ‘1990-1999’]

What actually happened:

<class 'list'>

['1912', '1929', '1913-1923', '1951', '1994', '1934', '1915', '1995', '1912', '1988', '2002', '1957-1959', '1955', '1970', '1990-1999']

hi @rashmi.chapke
tried your code. It works fine and the solution was accepted as well. Can you re-try again at your end? Make a hard refresh if required.

I refreshed it, now it accepted solution.
Thank you.