[Tutor] implied tuple in a list comprehension

Jim Mooney cybervigilante at gmail.com
Fri Aug 2 20:13:25 CEST 2013


On 2 August 2013 01:27, Steven D'Aprano <steve at pearwood.info> wrote:

> It makes perfect sense. You can try it yourself, if you pre-define some
> names that get used:
>
> idx = 42
> S = [(0, "fe"), (1, "fi"), (2, "fo"), (3, "fum")]
>
> x = [idx, (word for idx, word in S)]

Ack, I even made the original mistake, thinking word for idx, then
comma, then word in S, which made no sense, instead of unpacking -
word for (idx, word) in S. Done in again by the implied tuple ;')

Jim
---
If you sign a petition that usually says "People for Freedoms of blah,
blah, blah" and look into it, you may find the petitioner is a paid
shill for a giant company or organization, it has nothing to do with
people or freedom, and is positively damaging.
l.


More information about the Tutor mailing list