Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'else:': 0.03; 'subject:missing': 0.07; 'python': 0.08; 'am,': 0.12; 'def': 0.13; 'addendum:': 0.16; 'expression,': 0.16; 'idioms': 0.16; 'subject:Language': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'cc:2**0': 0.26; 'value.': 0.28; 'pass': 0.29; 'message-id:@mail.gmail.com': 0.29; '24,': 0.29; 'yield': 0.29; 'cc:addr:python.org': 0.29; 'email name:': 0.30; 'object.': 0.30; 'received:209.85.210.46': 0.30; 'received:mail- pz0-f46.google.com': 0.30; 'actually': 0.31; 'instead.': 0.32; "i've": 0.32; '----': 0.32; 'fri,': 0.34; 'follows:': 0.34; 'done': 0.34; 'anything': 0.34; 'try:': 0.34; 'something': 0.35; 'switch': 0.35; '(for': 0.35; 'received:google.com': 0.37; 'using': 0.37; 'received:209.85': 0.38; 'forgive': 0.38; 'sometimes': 0.38; 'except': 0.39; 'received:209': 0.39; 'header:Received:6': 0.61; 'custom': 0.61; 'subject:!': 0.66; 'soon': 0.72; 'min': 0.84; 'subject:types': 0.84 Received-SPF: pass (google.com: domain of jeanpierreda@gmail.com designates 10.68.132.102 as permitted sender) client-ip=10.68.132.102; Authentication-Results: mr.google.com; spf=pass (google.com: domain of jeanpierreda@gmail.com designates 10.68.132.102 as permitted sender) smtp.mail=jeanpierreda@gmail.com; dkim=pass header.i=jeanpierreda@gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=3ajmc9nBEjt3SBpUENpx/IimMvAbo73PwyCOxQtBv/0=; b=vk6hrT2x4jU3DlLwO91IvQ9vz02ORez61zFu3Fef8S7qyjlrImjRoPgtdZfWWdqp1c ibjtZ2QiDAm/k5W/Jd+YMoDnKvLSrjvkR13+zA4KlfaknfNr09HOdh9YZSfph8ShjSN3 oHU6F0hAn7io9XKzi2T3ck8fo5iolq0KNsrl8= MIME-Version: 1.0 In-Reply-To: <9qpkvkFberU1@mid.individual.net> References: <8c2096d9-3cc2-4b64-8f11-c1d958d94243@x19g2000yqh.googlegroups.com> <9qpkvkFberU1@mid.individual.net> From: Devin Jeanpierre Date: Fri, 24 Feb 2012 12:32:08 -0500 Subject: Re: PyWart: Language missing maximum constant of numeric types! To: Neil Cerutti Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1330104771 news.xs4all.nl 6973 [2001:888:2000:d::a6]:42667 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20827 On Fri, Feb 24, 2012 at 9:25 AM, Neil Cerutti wrote: > The only time I've naively pined for such a thing is when > misapplying C idioms for finding a minimum value. > > Python provides an excellent min implementation to use instead. min can be a little inconvenient. As soon as anything complicated has to be done during the min expression, you need to switch to using something else for sanity's sake. In that vein, I do actually sometimes use float('inf') (for numbers), or a custom max/min object. ---- Silly and completely nonserious addendum: Forgive me, I have spoken in error! min is the one true way, for you can still do it with a little wrangling, as follows: @operator.itemgetter(1) @min @apply def closest_object(): for x in xrange(board_width) for y in xrange(board_height): try: entity = board.get_entity(x, y) except EntityNotFound: pass else: yield distance(player.pos, entity.pos), entity Please don't kill me. -- Devin