14. Try it!


#1

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 (:


#2

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.


#3

Ah, I see, thanks for the quick answer


#4

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

this is my answer.


#5

I have that exact code and doesn't work... ?


#7
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 x**2, because I can't just use (lambda x**2... : 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.


#8

despair186 - my code is below. You don't need to use x**2 (or a variable set to it) in the lambda part. I think the x**2 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)


#9

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.


#10

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)


#11

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


#12

same here, really frustrating.
Tried using another browser and deleting cookies. Nothing helps. :confused:


#13

I reported it as a bug , hopefully it’ll get sorted out soon


#14

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


#15

I keep getting SCT Error as well :confused:


#16

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)


#17

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


#18

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?


#19

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


#20

The same problem even when I click Run without code.


#21

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.