Your code did not pass our answer checks(Pyspark)

Screen Link: https://app.dataquest.io/m/62/challenge%3A-transforming-hamlet-into-a-data-set/2/extract-line-numbers

My Code:

raw_hamlet = sc.textFile("hamlet.txt")
split_hamlet = raw_hamlet.map(lambda line: line.split('\t'))
split_hamlet.take(10)

def cleaner(element):
    element[0] = element.partition('@')[-1]
    return element 

hamlet_with_ids = split_hamlet.map(cleaner) 


I thought this is one of answers for this mission, but I got an message saying “Your code did not pass our answer checks”. Does this mean that my answer is wrong? Or it is related to the answer checking system?

Your code was’t correct. check the solution code.
hamlet_with_ids = split_hamlet.map(cleaner) you define the function cleaner() as def cleaner(element): that means it take an input called element, and you didn’t pass any argument to this parameter element when you are calling it inside the map function. And you have to use a lambda function with line variable to retrieve each line of your text file “hamlet.txt” mapping the function (to be created) with each line of the text file.
image

Here are a couple different ways to make this approach work. Pretty slick conversion really. The biggest thing was just that the function needs to be applied as a lambda function… I think.

def cleaner(element):
    element[0] = element[0].partition('@')[-1]
    return element 

hamlet_with_ids = split_hamlet.map(lambda x: cleaner(x))
hamlet_with_ids.take(10)

or

def clean(x):
    start = x[0]
    clean = start.partition('@')[-1]
    rest = x[1:]
    y = [clean] + rest
        
    return y

hamlet_with_ids = split_hamlet.map(lambda x: clean(x))
hamlet_with_ids.take(10)