how to do proper subclassing?

Larry Bates lbates at swamisoft.com
Tue Aug 3 13:50:42 EDT 2004


I think you want to have permfooation actually be
a list.  If you do then permfooation[1:3} will in
fact return a list [3,4].  If the permutation is
actually stored as:

[0 1 2 3 4]
[1 3 4 0 2]

You can get them into lists with:

f=open(inputfile)
lines=f.readlines()
f.close()
l=0
for line in lines:
    if l % 2 == 0: continue # skip first lines
    l+=1
    permfooation=[int(x) for x in line[1:-1].split()]

print permfooation[1:3]

Now you are probably going to want to wrap this into
a class for easier use.

HTH,
Larry Bates
Syscon, Inc.


"Jonas Koelker" <jonaskoelker at yahoo.com> wrote in message
news:mailman.1095.1091552353.5135.python-list at python.org...
> Hello there.
>
> I'm new to this list (/me welcomes himself).
>
> anyways, I'm having doubts about how to subclass
> properly. The big picture is that I want to handle
> permutations. As we all know, two popular notation
> forms exist: products of disjoint cycles ("(0 1 3)(2
> 4)") and 2*length matrices with the identity
> permutation as the first line ([0 1 2 3 4] over [1 3 4
> 0 2]). I find the latter more appropriate, since it's
> easy to store as a list (one can skip the first line,
> assuming it's _always_ the identity).
>
> However, I want the permutation to act like a list, in
> all those cases where I don't override the operations.
> For example, assuming permfooation is the above
> permutation [1 3 4 0 2], permfooation[1:3] should
> return [3,4]. How is this done? Do I have to actually
> implement a slice-mechanism in the permutation class?
>
> thanks,
>
> -- Jonas Kölker
>
>
>
>
>
> ___________________________________________________________ALL-NEW Yahoo!
Messenger - all new features - even more fun!  http://uk.messenger.yahoo.com





More information about the Python-list mailing list