Keeping two lists aligned after processing

philly_bob b0bm00r3 at gmail.com
Sun May 11 02:45:00 EDT 2008


On May 11, 2:32 am, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> philly_bob <b0bm0... 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.

The technique is described in this thread:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/ed652ba2fab47a6f/489f1746210e83b9?lnk=st&q=b0bm00r3#489f1746210e83b9

I've barely mastered it, but it does work.

Bob=



More information about the Python-list mailing list