Newbie: changing an attribute of objects in a list
Steven Taschuk
staschuk at telusplanet.net
Thu Jun 12 19:15:47 CEST 2003
Quoth Ben Simuyandi:
> Example objects in a list [a,b,...,i]:
[...]
Thanks!
There's two things I don't understand in your examples. One in
each, tidily enough.
In the first example, where all items start with .order == 1 and
the output is supposed to be
a.age == 100 a.order == 9
b.age == 200 b.order == 6
c.age == 300 c.order == 5
d.age == 400 d.order == 4
e.age == 500 e.order == 3
f.age == 600 f.order == 2
g.age == 50 g.order == 9
h.age == 700 h.order == 1
i.age == 150 i.order == 7
why do a and g get the same .order? I'd expected that we want
g.order == 9 and a.order == 8.
Then the second example, where we start with
[...]
d.age == 400 d.order == 4
e.age == 500 e.order == 4
f.age == 600 f.order == 5
g.age == 50 g.order == 6
h.age == 700 h.order == 7
i.age == 150 i.order == 8
and are to produce
[...]
d.age == 400 d.order == 4
e.age == 500 e.order == 5
f.age == 600 f.order == 6
g.age == 50 g.order == 7
h.age == 700 h.order == 8
i.age == 150 i.order == 9
Again the handling of g puzzles me. Here's my thinking:
1) d and e both have order 4; since d.age < e.age, we let d have
order 4 and bump e up to order 5.
2) Then e and f both have order 5; since e.age < f.age, we let e
have order 5 and bump f up to order 6.
3) Then f and g both have order 6. In the example posted, f gets
order 6 and g gets bumped up to order 7. But f.age > g.age, so I
expected g to take precedence for order 6.
What's going on here? I'm baffled.
--
Steven Taschuk staschuk at telusplanet.net
"[T]rue greatness is when your name is like ampere, watt, and fourier
-- when it's spelled with a lower case letter." -- R.W. Hamming
More information about the Python-list
mailing list