18/18 Error in the code


#1

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

THIS IS MY CODE
garbled = "IXXX aXXmX aXXXnXoXXXXXtXhXeXXXXrX sXXXXeXcXXXrXeXt mXXeXsXXXsXaXXXXXXgXeX!XX"

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

print remove_garbage(garbled)

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


#2

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

#3

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


#4

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

#5

It's working fine now


#6

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


#7

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)

#8

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


#9

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