Deutsch English Français Italiano |
<v4sois$1gqei$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Mark Bourne <nntp.mbourne@spamgourmet.com> Newsgroups: comp.lang.c Subject: Re: Baby X is bor nagain Date: Tue, 18 Jun 2024 20:52:58 +0100 Organization: A noiseless patient Spider Lines: 26 Message-ID: <v4sois$1gqei$1@dont-email.me> References: <v494f9$von8$1@dont-email.me> <v49seg$14cva$1@raubtier-asyl.eternal-september.org> <v49t6f$14i1o$1@dont-email.me> <v4bcbj$1gqlo$1@raubtier-asyl.eternal-september.org> <v4bh56$1hibd$1@dont-email.me> <v4c0mg$1kjmk$1@dont-email.me> <v4c8s4$1lki1$4@dont-email.me> <20240613002933.000075c5@yahoo.com> <v4emki$28d1b$1@dont-email.me> <20240613174354.00005498@yahoo.com> <v4okn9$flpo$2@dont-email.me> <20240617002924.597@kylheku.com> <v4pddb$m5th$1@dont-email.me> <20240618115650.00006e3f@yahoo.com> <v4rv0o$1b7h1$1@dont-email.me> <v4s370$1cgrl$1@dont-email.me> <v4sbir$1e579$1@dont-email.me> <6671ce83$0$3620715$882e4bbb@reader.netnews.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 18 Jun 2024 21:53:01 +0200 (CEST) Injection-Info: dont-email.me; posting-host="f6dfeab3d9e88a3420799621ce1dfd5f"; logging-data="1599954"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19JnauvHcscwNcHBr4Bc2c2" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 SeaMonkey/2.53.18.2 Cancel-Lock: sha1:L7Mg/k2GyALWI7lAZwBTU9bZQkM= In-Reply-To: <6671ce83$0$3620715$882e4bbb@reader.netnews.com> Bytes: 2359 DFS wrote: > On 6/18/2024 12:11 PM, David Brown wrote: > > >> if n % 2 == 1 : >> median = sorted(data)[n // 2] >> else : >> median = sum(sorted(data)[(n // 2 - 1) : (n // 2 + 1)]) / 2 > > I think your else formula (n % 2 == 0) is incorrect: > > n = 4 > data = [1,2,3,4] > median = 2.5 > > Yours appears to sum (1,2,3) = 6 / 2 = 3. > > Am I reading it correctly? Python ranges include the start index but exclude the end index. So data[1:3] gives the items at data[1] and data[2], but not data[3]. Indexes are zero-based, so data[1:3] == [2, 3], sum([2, 3]) == 5, and 5 / 2 == 2.5. -- Mark.