Newbie: changing an attribute of objects in a list

Ben Simuyandi bsimuyandi at africonnect.com
Fri Jun 13 04:37:57 EDT 2003


I'm very sorry about the confusion. It comes from mistyping, and not
thinking through my problem.

The first problem is from me not entering the number correctly. As you say,
it should be a.order = 8 and g.order =9.

As for the second problem, this is because I had not thought about *exactly*
what I want. What I would like is for the .age to be compared if any items
have matching .order values, and the object with the larger .age value to
have its .order value increased by one.

for example:
if d.order and e.order match
   compare d.age and e.age
      if d.age > e.age
        d.order = d.order + 1
      else if d.age < e.age
        e.order = e.order + 1

But after that, all objects with a .order value matching or greater than the
changed .order value with have to be increased by one as well, so that all
items still have a unique .order value. I don't actually need to compare
.age values any more.

example: (second example from previous email).


"Steven Taschuk" <staschuk at telusplanet.net> wrote in message
news:20030612111547.B902 at tibia.amotlpaa.bogus...
> 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
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>








More information about the Python-list mailing list