SRC: Music Synthesizer written in 100% Python

Jeffrey P Shell jeffrey at digicool.com
Mon Aug 28 12:43:34 EDT 2000


> > def pitchhz(note):
> >  if note=="A0":
> >   return 13.75
> >  if note=="A1":
> >   return 27.5
> >  if note=="A2":
> >   return 55.0
> >  if note=="A3":
> >   return 110.0
>
>
> how about something more along the lines of:
>
> def pitchhz(note):
>    return {
>        "A0" : 13.75,
>        "A1" : 27.5,
>        "A2" : 55.0,
>        ...
>    }[note]

Or even:  (for the increasingly_brave):

pitchhz = {
    "AO": 13.75,
    "A1": 27.5,
    "A2": 55.0
}.get

:)

>>> pitchhz("A1")
27.5
>>>


jeffr , http://euc.cx/





More information about the Python-list mailing list