[Tutor] Would somebody kindly...

Clayton Kirkwood crk at godblessthe.us
Wed Oct 29 00:13:19 CET 2014


Explain this double speak(>:

[pair for pair in values if key == pair[0]]

 

I understand the 'for pair in values'. I assume the first 'pair' creates the
namespace (although I am not sure how Python knows it's a tuple yet). I
think the outer [] make the line a comprehension ( If so, I don't seem to
get how/why a comprehension works), and probably make the line either a
tuple or list. The comprehension seems to act as a subroutine or macro( yes
I know those two words are meaningless in Python). I definitely am missing
the full meaning of the if statement. The example comes courtesy of Alan.

 

Thanks,

 

Clayton

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141028/a9d4ff3f/attachment.html>


More information about the Tutor mailing list