SRC: Music Synthesizer written in 100% Python

Michal Wallace sabren at manifestation.com
Tue Aug 29 22:43:33 EDT 2000


On 29 Aug 2000, Bernhard Herzog wrote:

> > > how about something more along the lines of:
> > >
> > > def pitchhz(note):
> > >    return {
> > >        "A0" : 13.75,
> > >        "A1" : 27.5,
> > >        "A2" : 55.0,
> > >        ...
> > >    }[note]
> 
> This solution is not much more efficient than the if-version and for all
> I know it might even be slower! The dictionary is constructed everytime
> the function is called and then only used to look up one value. Since
> the dict is constant, it should be put into a global variable, so that
> it's only created once.

Yeah, I was thinking about clarity, not efficiency. If I were really
doing it, I would just do:

pitchhz = {
   "A0" : 13.75,
   "A1" : 27.5
   ...
   }

blah = pitchhz[note]


Cheers,

- Michal
------------------------------------------------------------------------
www.manifestation.com  www.sabren.com  www.linkwatcher.com  www.zike.net
------------------------------------------------------------------------





More information about the Python-list mailing list