13. Extra Step / Question


#1

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?

https://www.codecademy.com/en/courses/python-beginner-en-KAgt5/3/2?curriculum_id=4f89dab3d788890003000096


#2

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.


#3

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