Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: Why Python 3? Date: Mon, 21 Apr 2014 11:56:43 +1200 Lines: 27 Message-ID: References: <7x8ur1esa5.fsf@ruckus.brouhaha.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net RVdJ5VEHTZOmCAEJNldxZQLM7cR5KzgJrBqRVgBW+k2+4SRntp Cancel-Lock: sha1:0a4BHLTSrjqSVsHvPvqJdAaCWu0= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: Xref: csiph.com comp.lang.python:70443 Ian Kelly wrote: > def average(values): > return sum(values) / len(values) > > This works for decimals, it works for fractions, it works for complex > numbers, it works for numpy types, and in Python 3 it works for ints. That depends on what you mean by "works". I would actually find it rather disturbing if an average() function implicitly used floor division when given all ints. The reason is that people often use ints as stand-ins for floats in computations that are conceptually non-integer. So a general-purpose function like average(), given a list of ints, has no way of knowing whether they're intended to be interpreted as ints or floats. To my way of thinking, floor division is a specialised operation that is only wanted in particular circumstances. It's rare that I would actually want it done in the context of taking an average, and if I do, I would rather be explicit about it using e.g. int(floor(average(...)) or a specialised int_average() function. -- Greg