Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.041 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'subject:Python': 0.06; 'subject:language': 0.09; 'python': 0.11; 'correctness': 0.16; 'formula': 0.16; 'subject: \n ': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'decimal': 0.31; 'steven': 0.31; 'fri,': 0.33; 'skip:d 20': 0.34; "can't": 0.35; 'received:google.com': 0.35; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'within': 0.65; 'subject:this': 0.83; 'actually,': 0.84; 'system:': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=wTWM9M5ac8MQN7x3RFngEA9zuNuxi4nfWsYS15Npme8=; b=R5ODG+bRI9KHTwInyrwspvb5mx0l8ATuq/JSQnYeT+BHXarij8XllbXkc4AdrkP6h8 Ka+6C9cqm1gWhuptRtLvTMlv4gDjPhRGkzaNjtkj1sd64AVS+PA0G1zcm7SkVGxFU5Pj 8mhJxNFLGQVy3DQ5OQ1x6sLPlqE8cLUZFvkybXnH0msNhf3sJCKcd9Bip/0G/Mzh03VQ 6/ygZTVlZKEQy0wD6WIcXfp6ykpo5tI072COTMxZHEUmE/R4w07CzIq6u0qMx3xMJHoV vFfGmFq34ClBQr4zoctvOiZhzq47pSIugny1ES8myxdpLeBsWE8YpPA+7lcGhersvZhG 5m2A== X-Received: by 10.66.240.70 with SMTP id vy6mr13342441pac.80.1396599233545; Fri, 04 Apr 2014 01:13:53 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <533e64ce$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <87ior3w740.fsf@elektro.pacujo.net> <5334c38e$0$29994$c3e8da3$5496439d@news.astraweb.com> <53364327$0$29994$c3e8da3$5496439d@news.astraweb.com> <53365F55.2040302@gmail.com> <533836c4$0$29994$c3e8da3$5496439d@news.astraweb.com> <533e64ce$0$29993$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Fri, 4 Apr 2014 02:13:13 -0600 Subject: Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396599236 news.xs4all.nl 2925 [2001:888:2000:d::a6]:41281 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69652 On Fri, Apr 4, 2014 at 1:52 AM, Steven D'Aprano wrote: > py> from decimal import * > py> getcontext().prec = 16 > py> x = Decimal("0.7777777777787516") > py> y = Decimal("0.7777777777787518") > py> (x + y) / 2 > Decimal('0.7777777777787515') > > "Guido, why can't Python do maths???" Well, you need to work within the system: >>> (5*x + 5*y) / 10 Decimal('0.7777777777787517') Actually, I have no idea whether that formula can be relied upon or the correctness of the above was just luck.