[Tutor] Would somebody kindly...

Clayton Kirkwood crk at godblessthe.us
Wed Oct 29 05:42:14 CET 2014



!-----Original Message-----
!From: Tutor [mailto:tutor-bounces+crk=godblessthe.us at python.org] On
!Behalf Of Dave Angel
!Sent: Tuesday, October 28, 2014 6:34 PM
!To: tutor at python.org
!Subject: Re: [Tutor] Would somebody kindly...
!
!
!>
! 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
!
!The namespace question depends on the version of Python. Python  2.x
!does not do any scoping.
!
!But in version 3.x, the variable pair will go away.
!
!So please tell us the version you're asking about.

I am using 3.4.1.

!
!The list comprehension always creates a list, not a tuple. Pair is  a
!tuple if and only if the corresponding element of values is a  tuple. In
!fact there's no requirement that those elements of  values have the same
!type. Of course if they're not of length 2,  then pair is a lousy name.
!And if one of them is not  subscriptable, then the if expression will
!blow up.
!
!
!--
!DaveA
!
!_______________________________________________
!Tutor maillist  -  Tutor at python.org
!To unsubscribe or change subscription options:
!https://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list