# 14. Try it!

Why does this code not work:

``````squares = [x ** 2 for x in range(1, 11)]
print filter(lambda x: squares[29:70], squares)
``````

Also, please explain the syntax for the lambda (:

You are supposed to print out the values in squares between 30 and 70, but you try to slice the list to print out the values with indexes between 30 and 70. Use <= to select the values from squares.

If you really wanted to print out the squares from index 30 to 70 you would also have to use `x in squares[30:70]`, because the lambda selects all x that make the statement behind the colon true.

2 Likes

Ah, I see, thanks for the quick answer

1 Like

squares = [x ** 2 for x in range(1,11)]
print filter(lambda x: x >= 30 and x <= 70 , squares)

1 Like

I have that exact code and doesn’t work… ?

``````squares=[x**2 for x in range(1,11)]
y=x**2
print filter(lambda y: y>=30 and y <=70, squares)
``````

I had to use another variable for x2, because I can’t just use (lambda x2… : and if I don’t use square, I get the results of x, not x**2. If there’s a shorter way to do it, I’ll be happy to learn.

2 Likes

despair186 - my code is below. You don’t need to use x2 (or a variable set to it) in the lambda part. I think the x2 is just used to populate the list. If you imagine the numbers in the list as digits, rather than the calculation, it helps separate the two in your mind.

i believe your ‘y=x**2’ is just ignored by the rest of the code. You could use any name for the lambda variable be it x, y or anything else.

squares = [x**2 for x in range(1,11)]

print filter(lambda x: x >= 30 and x <= 70, squares)

1 Like

spacecamel100,
I came up with the exact same code on my own (surprisingly, maybe some of this is beginning to stick.) It worked flawlessly to my surprise.

1 Like

I’m stuck. I’m using this code and it doesn’t work. I keep getting a “SCT Error.” In addition, it seems like there’s no way to advance in lessons, which completely kills my experience. Can anyone help please?

squares = [x ** 2 for x in range(1,11)]

print filter (lambda x: x >= 30 and x <= 70 , squares)

2 Likes

same issue here. I keep getting the ‘SCT error’, but its still printing the values in the list that its supposed to

2 Likes

same here, really frustrating.
Tried using another browser and deleting cookies. Nothing helps. I reported it as a bug , hopefully it’ll get sorted out soon

1 Like

Hi,
i am also facing same issue and reported as bug, can you pls tell me how much time it will take to sort out

I keep getting SCT Error as well same here with this code:

``````squares = [x ** 2 for x in range(1,11)]
print squares
print filter (lambda x: x >= 30 and x <= 70, squares)
``````

(I use the “print” just to check the results)

@coursemaster09509 did the matter resolve? I am also getting the same SCT error.

NEED HELP:
Below is the code that I use, but I always end up getting an SCT error.

squares = [x ** 2 for x in range(1,11)]

print filter (lambda x: x >= 30 and x <= 70 , squares)

Does anyone have have a solution that works?

did you get an answer for this problem?
I am stuck on the same issue.

The same problem even when I click Run without code.

It didn’t work yesterday (as I’ve written above) but just now it worked so if it was indeed a problem on their end, thank you guys for the bug reports and I hope it works for you too if you try again.