17:14 Try it!


#1




When I submit my code:

squares = [x**2 for x in range(1,11)]
filter(lambda x: x in range(30,71), squares)

I got the error message as:
Oops, try again. It looks like you didn't print the correctly filtered list to the console.

I ran it in command line and the result is correct:

squares = [x**2 for x in range(1,11)]
print squares
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
filter(lambda x: x in range(30,71), squares)
[36, 49, 64]

Wonder why I got error message??
Thanks


#2

In Python we can actually do this with an inequality.

30 < x < 70

That is not the issue, though. Did you print the filter output?


#3

Yes, it printed out correctly as the last line:

squares = [x**2 for x in range(1,11)]
print squares
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
filter(lambda x: x in range(30,71), squares)
[36, 49, 64]


#4

You may be seeing console echo of the last assignment. We do need to print the filtered result in a statement.

print filter( ... )

#5

Thank you! I missed the print before filter :grin:.


#6

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