14. Try It!


I get what lambda is and what it does but when I try it on idle 3 it gives me a strange output. for example see code below.

I expected to see a list of [0,3,6,9,12,15]

Am I writing the wrong syntax for python3?

languages =["html", "java", "python", "ruby"]
filter (lambda x: x=="python", languages)
<filter object at 0x10558ed30>


you need to use print:

print(filter (lambda x: x=="python", languages))

to print the result of the filter

Otherwise, it will just show you information about the filter object


I did just now but result is still the same?

print (filter(lambda x: x=="python", languages))


<filter object at 0x10558ee80


it seems some changes where made to the behaviour of filter:


In exercise 18. Lambda Expressions I have a similar problem. I pass the test on code academy with the following code:

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

and I get:
I am another secret message!

but when I write the same code on idle 3.x with list(filter), I am getting a list since I use list. Is there any other way to get the same output as in code academy?

my idle 3 code and the output:

>>> message_3=list(filter(lambda x: x!="X", garbled))
>>> print (message_3)
['I', ' ', 'a', 'm', ' ', 'a', 'n', 'o', 't', 'h', 'e', 'r', ' ', 's', 'e', 'c', 'r', 'e', 't', ' ', 'm', 'e', 's', 's', 'a', 'g', 'e', '!']


you can also run your code in python2?

python3 made some changes, nothing we can do about this.

for your secret message, why use list(), why not str()?


Nope, even with str() it gives me .

in python 2 (I mean codecademy exercise) it works just fine.

Any other bright ideas?


this sucks, this works:

message_3=filter(lambda x: x!="X", garbled)
print ("".join(list(message_3)))

but its not really nice

this is what the python docs say:

map() and filter() return iterators. If you really need a list, a quick fix is e.g. list(map(...)), but a better fix is often to use a list comprehension (especially when the original code uses lambda), or rewriting the code so it doesn’t need a list at all. Particularly tricky is map() invoked for the side effects of the function; the correct transformation is to use a regular for loop (since creating a list would just be wasteful).



many thanks!!! Since you always provide very helpful comments do you mind looking at the following thread and advise me which interpretor to use?

sorry for the off topic help request. thx in advance!



I am learning python on codecademy. As additional testing I have idle 3.5.2 on my mac air and use the idle from time to time. however certain symbols e.g. ~ or ^ or even {} makes idle immediately crash on my mac.

Does any one have any idea why this is so?

dle is a python module, so you'd debug it the same way as any other python code

Since you ask, it's probably not something you want to dig into.

You're probably better off upgrading to a better editor anyhow, idle is kind of just for when the alternative is Notepad.exe

do you have any suggestions as a better editor? would be great to have one where I can also see the interpreter separately - just like in codecademy!


i saw the topic, i don't have a clue what is causing the crash


Could you please then suggest an interpreter to use? Which one are you using?


i would suggest trying to figure out why python is crashing