On 28Oct2014 18:02, Clayton Kirkwood <c...@godblessthe.us> wrote:
!> Explain this double speak(>:
!>
Ah, Alan sent an answer also, but this one answers the last tidbit. Alan had
the some_list and pair the same name, presumably creating a temporary tuple and
when the loop is done, the temporary replaces the original.
Let me try a less wordy diagram. You will need to be displaying in a constant
width font :-)
[ pair for pair in values if key == pair[0] ]
^^^^-- the expression that accrues in the resulting list
^^^^-- the loop variable, taken from the loop source values
^^^^^^-- the loop source values
^^^^^^^^^^^^^^-- condition for including the
expression in the resulting list
So that first "pair" could be any expression, it is almost only coincidence
that it is the same as the loop variable. It is the same in this case because
this is the idiomatic way to select particular values form an existing list.
If we'd wanted the new list to contain double the original values we'd write:
[ pair*2 for pair in values if key == pair[0] ]
Cheers,
Cameron Simpson <c...@zip.com.au>
ERROR 155 - You can't do that. - Data General S200 Fortran error code list
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor