Keeping two lists aligned after processing

Paul Rubin http
Sun May 11 02:32:35 EDT 2008


philly_bob <b0bm00r3 at gmail.com> writes:
> algs=['AlgA', 'AlgB', 'AlgC', 'AlgD', 'AlgE']
> accs=[]
> for alg in algs:
>    thisacc=getattr(alg.accuracy)()   # picked this technique on
> comp.lang.python last month
>    accs.append(thisacc)

I think what you mean is (untested):

     algs = [AlgA, AlgB, AlgC, AlgD, AlgE]
     accs = sorted(((alg.accuracy(), alg.name()) for alg in algs),
                   reverse=True)
     for i,(alg_acc, alg_name) in enumerate(accs):
        print '%2d %5s %0.2f'% (i, alg_name, alg_acc)

This assumes a method alg.name() which tells you the name of the
algorithm.  I don't understand how you're converting the string 'AlgA'
to an algorithm object in your example above.



More information about the Python-list mailing list