> 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
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
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
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
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
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
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
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
[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:
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
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'), ('
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
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:
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
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
15 matches
Mail list logo