Lambda is "simply" another way of creating a function, maybe it's even faster.
Q: Okay, I knew that already but how does it prints only specific values? And what is that "squares" used for?
A: It works this way: you'll first check if each element at squares, which is your iterable, follows your conditions which is to be greater or equal to 30 and less or equal to 70. If that so, it will return the value of it.
But will your condition be followed if I don't use filter()? No. The function filter()which will filter, oh well couldn't really find another way to say this, the elements that will be returned. It's a similar idea to store specific values into a list if they follow a condition, where you check using an if statement.
In fact if you try to print:
print lambda x: x >= 30 and x <= 70, squares
You'll get all the values that are in squares plus something like this:
#Had to add spaces between '<' and '>' otherwise it wouldn't show up here
#but in your compiler, it will show up with those spaces.
function < lambda > at 0x115b160
But if you try to print:
print filter(lambda x: x >= 30 and x <= 70, squares)
You'll get a list contaning the elements that follow your conditions.
Here's the definition of the function filter():
Construct a list from those elements of iterable for which function returns true. iterable may be either a sequence, a container which supports iteration, or an iterator. If iterable is a string or a tuple, the result also has that type; otherwise it is always a list.
Just for the record: if you try to store lambda x: x >= 30 and x <= 70, squares into a variable and use type(), you'll see your variable is a tuple, since you'll have the place in memory where your lambda is and the values from the list.
But if you store filter(lambda x: x >= 30 and x <= 70, squares) into a variable and use type(), you'll see your variable is now a list where you'll be able to do all that list manipulation things that are asked for you to do every now and then.
If I wasn't clear at a certain point or my answer wasn't good, let me know and I'll find another way to explain!
Edit: filter() function definition