"함수 median()"의 두 판 사이의 차이

1번째 줄: 1번째 줄:
[[category: Math]]
[[category: Math]]
==Excel==
[[category: Excel]]
<source lang='php'>
=MEDIAN(11, 1, 2, 12)
// 6.5
=MEDIAN(11, 1, 2)
// 2
</source>


==Python==
==Python==

2014년 5월 31일 (토) 22:07 판


1 Excel

PHP
Copy
=MEDIAN(11, 1, 2, 12)
// 6.5
=MEDIAN(11, 1, 2)
// 2

2 Python

Python
Copy
def median(lst):
    lst_len = len(lst)
    lst = sorted(lst)
    if lst_len % 2 == 0:
        return (lst[lst_len/2-1]+lst[lst_len/2])/2.0
    return lst[lst_len/2]

print median([11, 1, 2, 12])
# 6.5
print median([11, 1, 12])
# 11

3 같이 보기