In page 29 of the third edition of the Python Cookbook, the author makes the following statement:
"... might also be done by creating a sequence of tuples and passing them to the
dict()
function. For example:
p1 = dict((key, value) for key, value in prices.items() if value > 200)
The author's referral of the argument passed to the dict()
constructor as a "sequence" kinda got me wondering... what exactly is for ... in ...
? It isn't an expression is it? One can't just type into a Python interpreter: for x in (1,2,3)
and receive a result? The documentation for list()
, for example suggests constructor expects an iterable but it's unclear to me what's going on.