how to do proper subclassing?
lbates at swamisoft.com
Tue Aug 3 19:50:42 CEST 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:
for line in lines:
if l % 2 == 0: continue # skip first lines
permfooation=[int(x) for x in line[1:-1].split()]
Now you are probably going to want to wrap this into
a class for easier use.
"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?
> -- Jonas Kölker
> ___________________________________________________________ALL-NEW Yahoo!
Messenger - all new features - even more fun! http://uk.messenger.yahoo.com
More information about the Python-list