18/18 Error in the code


I have written this code without using lambda expression ....Bt its not working ,,,Can anyone tell me what is the error...Also suggest the lambda expression method


def remove_garbage(garbled) :
message = ""
for char in garbled :
if char != 'X' :
message += char
return message

print remove_garbage(garbled)

Oops, try again. It looks like your message is "" instead of "I am another secret message!"


When they test your code for that section they are checking for what the variable message contains and since you have no variable message contain the tester sees nothing hence you get that error
if do not want to use lambdas you ought to do this

message = remove_garbage(garbled)
print message


thanks rydan ....the error that I was getting is removed
Bt now I am getting the following error message in the pop up

Oops, try again. Make sure to call the filter() function!
I think the program is asking to make use of the lambda expression ...so can u suggest that method
I will be thankful to u


Okay that's weird I tested it and it worked. it seem you have to use lambdas

message = filter(lambda x: x!="X", garbled)
print message


It's working fine now


My weirdness on this question was pretty simple - I misspelled "lambda". Doh!


You really ought to do what the section suggests, having finished most of it.
Use lambdas, they're much simpler (and that's what you're supposed to be using)

message = filter(lambda x: x != "X", garbled)


Just to add, if you don't define the variable "message", as per the instruction, and directly print the result of filter, you will see correct output but the submission will not be accepted. So, define "message" and print that


Yeah you could make the first one work I guess by manipulating the string to go backwards initially. But the lambda method is by far much better though.

garbled = "!XeXgXaXsXsXeXmX XtXeXrXcXeXsX XeXhXtX XmXaX XI"
garbled = garbled[::-1]
def remove_garbage(garbled):
    message = ""
    for char in garbled:
        if char != "X":
            message += char
    return message