Sujet : Re: Baby X is bor nagain
De : nospam (at) *nospam* dfs.com (DFS)
Groupes : comp.lang.cDate : 18. Jun 2024, 19:14:27
Autres entêtes
Message-ID : <6671ce83$0$3620715$882e4bbb@reader.netnews.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
User-Agent : Betterbird (Windows)
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?