Code style query: multiple assignments in if/elif tree

David Hutto dwightdhutto at gmail.com
Tue Apr 1 02:05:17 EDT 2014


On Tue, Apr 1, 2014 at 1:45 AM, Rustom Mody <rustompmody at gmail.com> wrote:

> On Tue, Apr 1, 2014 at 3:26 PM, Steven D'Aprano  wrote:
>
> > Haskell has nifty pattern-matching syntax for this that looks quite close
> > to the mathematical hybrid function syntax, but in Python, we're limited
> > to explicitly using an if. If I were coding this, and I'm not, I'd wrap
> > it in a function. One advantage of a state variable rather than a
> > continuous time function is that we can do this:
> > def accel(state):
> >     return {NO_BRAKING: 0.0,
> >             LOW_BRAKING: 0.2,
> >             MID_BRAKING: 0.425,
> >             HIGH_BRAKING: 0.85}[state]
>
> Neat
> I would put the dict in a variable. And those _BRAKINGs are GALLing me!
>
> breaking = {NO:0.0, LOW:0.2, MID:0.425:, HIGH:0.85}
> def accel(state): return breaking[state]
>
> <Irony>
> In using Haskell, I often wish for dicts especially python's nifty
> dict-literals
> </Irony>
>
>
This still omits the viscosity(+-) of the enclosed, or exposed
track/environmental variables of the system in which the objects traveling.

http://www.synlube.com/viscosit.htm

> --
>


> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com <http://www.hitwebdevelopment.com>*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140401/e992808f/attachment.html>


More information about the Python-list mailing list