Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!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.039 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.05; 'works.': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.16; 'library,': 0.18; 'language': 0.19; '(or': 0.21; 'lawrence': 0.22; 'tried': 0.24; 'header:In-Reply-To:1': 0.24; '(this': 0.24; 'written': 0.24; 'wondering': 0.25; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'this.': 0.28; "i'm": 0.29; 'convert': 0.29; 'values': 0.30; 'you?': 0.32; 'language.': 0.32; 'to:addr :python-list': 0.35; 'there': 0.36; '(and': 0.36; 'subject:" ': 0.36; 'received:org': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'sure': 0.40; 'where': 0.40; 'mark': 0.40; 'called': 0.40; 'further': 0.60; 'even': 0.61; 'places': 0.64; 'our': 0.64; 'charset:windows-1252': 0.65; 'music': 0.78; '12:': 0.84; 'pythonistas,': 0.84; 'do:': 0.91; 'ranging': 0.91; 'subject:value': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: "normalizing" a value Date: Thu, 02 Jul 2015 05:41:31 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-21-40.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1435812108 news.xs4all.nl 2850 [2001:888:2000:d::a6]:42171 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3477 X-Received-Body-CRC: 1348636553 Xref: csiph.com comp.lang.python:93411 On 02/07/2015 01:12, bvdp wrote: > Not sure what this is called (and I'm sure it's not normalize). Perhaps "scaling"? > > Anyway, I need to convert various values ranging from around -50 to 50 to an 0 to 12 range (this is part of a MIDI music program). I have a number of places where I do: > > while x < 0: x += 12 > while x >= 12: x -= 12 > > Okay, that works. Just wondering if there is an easier (or faster) way to accomplish this. > Further to other answers have you tried looking for a library, or even just a recipe, that has already been written and tested that does this for you? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence