13. Extra Step / Question


I've passed the lesson, it seems pretty straight forward but then I was trying a few other scenarios which i was surprised that it never worked. Can you not do something like...

languages = ["HTML", "JavaScript", "Python", "Ruby"]
print filter(lambda i: i%2==0, languages)

... so that the list prints indexes that are even. The above should print HTML & Python. How can we do something like this, or is it not allowed?



If you're to use filter then you would need access to the indexes, naming your parameter i doesn't change what filter passes as an argument to your function (see documentation for filter for a description of what exactly it does)

List slicing would be a more direct approach.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.