[portland] Dictionary As Switch Statement

Rich Shepard rshepard at appl-ecosys.com
Fri Jan 18 01:16:46 CET 2008


   I want to use a dictionary to select the appropriate function to call
based on the key value. However, I'm missing something simple here as I try
to implement it.

   The dictionary:

     curvePlot = {
       'Decay S-Curve'     : zCurve(self),
       'Bell Curve'        : bellCurve(self),
       'Growth S-Curve'    : sCurve(self),
       'Beta'              : betaCurve(self),
       'Data'              : dataCurve(self),
       'Linear Increasing' : linIncrCurve(self),
       'Linear Decreasing' : linDecrCurve(self),
       'Left Shoulder'     : leftShouldCurve(self),
       'Trapezoid'         : trapCurve(self),
       'Right Shoulder'    : rightShouldCurve(self),
       'Triangle'          : triangCurve(self),
       'Singleton'         : singleCurve(self),
       'Rectangle'         : rectCurve(self),
       'Outcome'           : resultsCurve(self)
       }

   I can print out the keys, in a different order; 'print curvePlot.keys()'
yields:

['Left Shoulder', 'Singleton', 'Outcome', 'Bell Curve', 'Right
Shoulder', 'Growth S-Curve', 'Beta', 'Linear Increasing', 'Decay S-Curve',
'Linear Decreasing', 'Trapezoid', 'Triangle', 'Data', 'Rectangle']

   But, when I try to print the entire dictionary, the values are not shown;
'print curvePlot' produces:

{'Left Shoulder': None, 'Singleton': None, 'Outcome': None, 'Bell Curve':
None, 'Right Shoulder': None, 'Growth S-Curve': None, 'Beta': None, 'Linear
Increasing': None, 'Decay S-Curve': None, 'Linear Decreasing': None,
'Trapezoid': None, 'Triangle': None, 'Data': None, 'Rectangle': None}

   What have I done incorrectly that I cannot produce the value for a given
key? When I pass the value of the key (it's the fifth item in a tuple so
it's addressed as 'row[4]') all I get is 'None.'

Rich

-- 
Richard B. Shepard, Ph.D.               |  Integrity            Credibility
Applied Ecosystem Services, Inc.        |            Innovation
<http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863


More information about the Portland mailing list