Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'syntax': 0.04; 'explicitly': 0.05; 'subject:query': 0.07; 'variables': 0.07; 'cc:addr:python-list': 0.11; 'def': 0.12; 'dict': 0.16; 'haskell,': 0.16; 'syntax,': 0.16; 'variable.': 0.16; 'wrote:': 0.18; 'variable': 0.18; "python's": 0.19; 'not,': 0.20; 'coding': 0.22; 'cc:addr:python.org': 0.22; 'mathematical': 0.24; 'subject:Code': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; '>': 0.26; 'this:': 0.26; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'especially': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'breaking': 0.31; "d'aprano": 0.31; 'steven': 0.31; "we're": 0.32; 'quite': 0.32; 'url:python': 0.33; "i'd": 0.34; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'skip:& 10': 0.38; 'pm,': 0.38; 'rather': 0.38; '8bit%:6': 0.40; 'url:mail': 0.40; 'to:addr:gmail.com': 0.65; 'close': 0.67; 'continuous': 0.68; 'wish': 0.70; 'url:htm': 0.73; 'me!': 0.84; 'traveling.': 0.84; '<>*': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=2ylf5t6yoV3MvraNypNbcosmqkHF8S9qLpDHbK/Xsto=; b=zabBTW6Mc08pW9y9GuEfmeu83Are/gdeZG32wiymswcrZLPV43jLuamx8xvi8ufQAE qOwhBoM8s+8FNdVvbjESn7S/6Lx9kMzJDjziQmks82CgiEVeN4jkloA55VQUrpe5Cm6/ C529H6QrNkvBl8LQDZYz8qlJcsVSb2ztQnNvZXaBjmPMmhgGbWzTnhPOjg6EOUvt290l 2zwfTrQrNq/vmpXLJrvYU1oukAzEIJee+Egyl+ZqhZ9mQcVQrTFyZ07kAAnpnqeE7RFU 1H1StWC0RLuEtCnnSSiWIkz8VNDNJAzJmMXRR6PagBt3TBCFAGGCOzlXa01WfPh2wWwQ 8ZWQ== MIME-Version: 1.0 X-Received: by 10.224.14.135 with SMTP id g7mr12684qaa.91.1396332318008; Mon, 31 Mar 2014 23:05:18 -0700 (PDT) In-Reply-To: <0f01ed1d-bc24-4286-8d1c-bfee7baedbc2@googlegroups.com> References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <0f01ed1d-bc24-4286-8d1c-bfee7baedbc2@googlegroups.com> Date: Tue, 1 Apr 2014 02:05:17 -0400 Subject: Re: Code style query: multiple assignments in if/elif tree From: David Hutto To: Rustom Mody Content-Type: multipart/alternative; boundary=047d7bdc8f8ccda9f304f5f4f36d Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 110 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396332327 news.xs4all.nl 2951 [2001:888:2000:d::a6]:34045 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69472 --047d7bdc8f8ccda9f304f5f4f36d Content-Type: text/plain; charset=ISO-8859-1 On Tue, Apr 1, 2014 at 1:45 AM, Rustom Mody 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] > > > In using Haskell, I often wish for dicts especially python's nifty > dict-literals > > > 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 * --047d7bdc8f8ccda9f304f5f4f36d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Tue, Apr 1, 2014 at 1:45 AM, Rustom Mody <<= a href=3D"mailto:rustompmody@gmail.com" target=3D"_blank">rustompmody@gmail= .com> wrote:
On Tue, Apr 1, 2014 at 3:26 PM, Steven D'Aprano = =A0wrote:

> Haskell has nifty pattern-matching syntax for this that looks quite cl= ose
> to the mathematical hybrid function syntax, but in Python, we're l= imited
> to explicitly using an if. If I were coding this, and I'm not, I&#= 39;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):
> =A0 =A0 return {NO_BRAKING: 0.0,
> =A0 =A0 =A0 =A0 =A0 =A0 LOW_BRAKING: 0.2,
> =A0 =A0 =A0 =A0 =A0 =A0 MID_BRAKING: 0.425,
> =A0 =A0 =A0 =A0 =A0 =A0 HIGH_BRAKING: 0.85}[state]

Neat
I would put the dict in a variable. And those _BRAKINGs are GALLing me!

breaking =3D {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(+-)=A0of the enclosed, or exposed trac= k/environmental variables of the system=A0in which the objects traveling.
--
=A0
https://mail.python.org/mailman/listinfo/python-list



--
Best Rega= rds,
David Hutto<= /span>
CEO: http://www.hitwebdevelopment.com
--047d7bdc8f8ccda9f304f5f4f36d--