Re: why does this unpacking work

2006-11-07 Thread Piet van Oostrum
> Carsten Haese <[EMAIL PROTECTED]> (CH) wrote: >CH> On Fri, 2006-10-20 at 15:14, John Salerno wrote: >>> What seems to be happening is that 'for x,y in t' is acting like: >>> >>> for x in t: >>> for y,z in x: >>> #then it does it correctly >CH> No, it's actually behaving like >CH> for x i

Re: why does this unpacking work

2006-10-21 Thread Bruno Desthuilliers
John Salerno a écrit : > [EMAIL PROTECTED] wrote: > >> It's just sequence unpacking. Did you know that this works?: >> >> pair = ("California","San Francisco") >> state, city = pair >> print city >> # 'San Francisco' >> print state >> # 'California' > > > Yes, I understand that. What confused m

Re: why does this unpacking work

2006-10-20 Thread Fredrik Lundh
John Salerno wrote: > I understand that t returns a single tuple that contains other tuples. t *is* a single tuple that contains other tuples. > Then 'for x in t' returns the nested tuples themselves. > > But what I don't understand is why you can use 'for x,y in t' when t > really only retur

Re: why does this unpacking work

2006-10-20 Thread Paddy
John Salerno wrote: > I'm a little confused, but I'm sure this is something trivial. I'm > confused about why this works: > > >>> t = (('hello', 'goodbye'), > ('more', 'less'), > ('something', 'nothing'), > ('good', 'bad')) > >>> t > (('hello', 'goodbye'), ('more', 'less'), ('so

Re: why does this unpacking work

2006-10-20 Thread John Salerno
Marc 'BlackJack' Rintsch wrote: > Uhm, you mean:: > > pair = (("California","San Francisco"),) > > Note the extra comma to make that "a tuple in a tuple". > > Ciao, > Marc 'BlackJack' Rintsch You're right! -- http://mail.python.org/mailman/listinfo/python-list

Re: why does this unpacking work

2006-10-20 Thread Gabriel Genellina
At Friday 20/10/2006 17:29, John Salerno wrote: I was expecting 't' to be a two-tuple for it to work. Maybe writing it as: for (x,y) in t sort of helps to show that '(x,y)' is equivalent to one object in 't'. That makes it look a little more cohesive in my mind, I guess, or helps me to see it

Re: why does this unpacking work

2006-10-20 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, John Salerno wrote: > [EMAIL PROTECTED] wrote: >> It's just sequence unpacking. Did you know that this works?: >> >> pair = ("California","San Francisco") >> state, city = pair >> print city >> # 'San Francisco' >> print state >> # 'California' > > Yes, I understand that

Re: why does this unpacking work

2006-10-20 Thread John Salerno
Carsten Haese wrote: > You seem to have difficulty distinguishing the concept of looping over a > tuple from the concept of unpacking a tuple. I think you're right. It's starting to make more sense now. I think when I saw: for x,y in t I was expecting 't' to be a two-tuple for it to work. May

Re: why does this unpacking work

2006-10-20 Thread John Salerno
[EMAIL PROTECTED] wrote: > It's just sequence unpacking. Did you know that this works?: > > pair = ("California","San Francisco") > state, city = pair > print city > # 'San Francisco' > print state > # 'California' Yes, I understand that. What confused me was if it had been written like this:

Re: why does this unpacking work

2006-10-20 Thread Gabriel Genellina
At Friday 20/10/2006 16:14, John Salerno wrote: I'm a little confused, but I'm sure this is something trivial. I'm confused about why this works: >>> t = (('hello', 'goodbye'), ('more', 'less'), ('something', 'nothing'), ('good', 'bad')) I understand that t returns a single t

Re: why does this unpacking work

2006-10-20 Thread Jon Clements
John Salerno wrote: > I'm a little confused, but I'm sure this is something trivial. I'm > confused about why this works: > > >>> t = (('hello', 'goodbye'), > ('more', 'less'), > ('something', 'nothing'), > ('good', 'bad')) > >>> t > (('hello', 'goodbye'), ('more', 'less'), ('

Re: why does this unpacking work

2006-10-20 Thread Carsten Haese
On Fri, 2006-10-20 at 15:37, Carsten Haese wrote: > for x in t: > y,z = t > # do something with y and z Typo here, of course I mean y,z = x. -Carsten -- http://mail.python.org/mailman/listinfo/python-list

Re: why does this unpacking work

2006-10-20 Thread johnzenger
It's just sequence unpacking. Did you know that this works?: pair = ("California","San Francisco") state, city = pair print city # 'San Francisco' print state # 'California' John Salerno wrote: > I'm a little confused, but I'm sure this is something trivial. I'm > confused about why this works:

Re: why does this unpacking work

2006-10-20 Thread Carsten Haese
On Fri, 2006-10-20 at 15:14, John Salerno wrote: > I'm a little confused, but I'm sure this is something trivial. I'm > confused about why this works: > > >>> t = (('hello', 'goodbye'), > ('more', 'less'), > ('something', 'nothing'), > ('good', 'bad')) > >>> t > (('hello', 'go

why does this unpacking work

2006-10-20 Thread John Salerno
I'm a little confused, but I'm sure this is something trivial. I'm confused about why this works: >>> t = (('hello', 'goodbye'), ('more', 'less'), ('something', 'nothing'), ('good', 'bad')) >>> t (('hello', 'goodbye'), ('more', 'less'), ('something', 'nothing'), ('good', 'bad